- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report
I have a WPF application in which I have implemented the MVVM pattern. I have a window that has a textbox bound to a string property that in a round about way is populated by the user pressing a button which brings up a promptentity.
That's kind of besides the point. I populate the text box with the value of the selected block attribute reference, and the user is allowed to modify it in any way that they like, then they press another button to apply their changes back to the block attribute reference. This runs another method that passes the new value into the block and voila it works.
When writing this code I realized that the attribute value, or I guess the state of the AutoCAD drawing itself, won't change unless the user clicks back focus into AutoCAD from my WPF window, and then the change "kicks in" and becomes visible.
I decided to make this a seamless process so at the end of my method that updates the block attribute reference I call
Autodesk.AutoCAD.Internal.Utils.SetFocusToDwgView();
From the user's perspective the update is seamless.
So that's all fine and dandy but then I wanted to get fancy and thought, hey I want to make it so that when my user is typing in the textbox on my application, AutoCAD is updating in real-time. This allows them to see the changes that they are making in terms of spacing and new lines and all that as it's rather important to know that stuff.
I implemented something from expression blend into my TextBox that looks like this:
<i:Interaction.Triggers> <i:EventTrigger EventName="TextChanged"> <i:InvokeCommandAction Command="{Binding UpdateAttributeValuesCommand}" /> </i:EventTrigger> </i:Interaction.Triggers>
The idea now is that every time the text changes in the text box (from the user typing in stuff) the command to update the block attribute will run and they should see the block changing in real time. This of course does not work when the code also tells AutoCAD to steal focus. And if I don't tell AutoCAD to steal focus, the user can type all they want, but the change won't be reflected in the drawing until they click over in AutoCAD to bring it back into focus, which defeats the entire purpose of what I'm trying to do.
So my question is, is there any way I can get AutoCAD to update it's state without having to give it focus or steal focus away from my application?
Solved! Go to Solution.