This thread looks to be a little on the old side and therefore may no longer be relevant. Please see if there is a newer thread on the subject and ensure you're using the most recent build of any software if your question regards a particular product.
This thread has been locked and is no longer accepting new posts, if you have a question regarding this topic please email us at support@mindscape.co.nz
|
Hello, Since I put a nightly build, I see a Textbox at the beginning of a Connection Line. It's a very good idea. I understood that it is the Data of the Connection. But I have some questions : can I replace the Textbox by a ComboBox ? And then, according to the Data value (set by the ComboBox), set the color of the Connection Line? For example : we have choice between Green & Red in the ComboBox, and then it could change the color of the Connection Line (= Arrow). Thank you |
|
|
Hello Leon Yes this is possible. Start by including this code in a resource dictionary along with your other styling code:
Next, on your DiagramFormatter, set the ConnectionContentTemplateSelector property to be the fixed template selector (seen at the end of the above code). Change the background color of the TextBox (to something that will stand out) and run your application to see that everything is being applied correctly. Once it is working, you can start to replace the TextBox in the template with a ComboBox instead. It's selected value can have a two way binding with the Data property of the connection (like what the TextBox is currently doing). Once you are using a ComboBox, you could get ride of the ContentTextBoxStyle code above, as well as the BorderBrush setters within the triggers as you may not need these any more (depending on how you want the combo boxes to look). Then you can change the color of the connection line based on the Data property, similar to what you did with the arrow head colors. Let me know if you have questions about these steps. -Jason Fauchelle |
|
|
Hi Jason thanks for your answer. In your code, are you sure it's 'f' and not 'ms' in :
Because with 'f', it doesn't compile. Then, I tried this, with less code, to simply show you :
The Combobox works (and shows), then, if I select a ComboBoxItem, Data gets the selected value, but I tried to bind "Data" or "Data.ToString" or "Data.ToString()" in my ConnectionStyle, and it doesn't work :
Maybe do you know why it doesn't work? Thank you |
|
|
Hello Leon Yes you are right, the f: should be ms:. I had copied this from our core styles which uses f: in some places. To get the binding in the style to work, use this: {Binding Connection.Data, RelativeSource={RelativeSource Self}}. This is because the source of the binding is a DiagramConnectionElement which is the visual element of the connection. The Data property is on the model, which can be accessed through the Connection property of the visual. I can see that this could be confusing because in the arrow head scenario, the FromConnectionPoint property happens to be on both the visual as well as the model. Let me know if you have questions about other binding scenarios. -Jason Fauchelle |
|
|
It works. Thank you for your help. But I have another problem : when the Data value change, the arrow change color. It's OK, and then the connection is selected. Then, if I do a click outside the connection (to unselect it), the Combobox Data value hides. It's blank : the selected value disappears (but the connection has still the good color). Do you know why it happens? Thank you |
|
|
Hello Leon Yes, you'll want to set the binding on the SelectedValue property of the ComboBox in your ConnectionContentTemplate, rather than the Text property. That should fix it up. -Jason Fauchelle |
|
|
Hi Jason, I tried:
I tried with Text and SelectemValue too at the same time. Then I tried with :
instead of
too, but it doesn't work. It tried with SelectedItem too, but no success. Actually, when I create a Connection, it's red (default value). When I click an Item ('Green' for exemple) of the Combobox, its value appears in it (we can read 'Green') and the Connection color change (in green). And then, if a do a Click with my mouse outside the Connection line, it unselects the Connection line and the Combobox Value disappear (we can't read 'Green' anymore, the field becomes empty). But the Connection.Data value keeps its good 'Green' value (because the Connection keeps its green color). I really don't know why it happens... Leon |
|
|
Hello Leon Sorry, I did not actually try this earlier. It turns out that when populating a ComboBox with ComboBoxItems manually (rather than using ItemsSource) you will also need to set SelectedValuePath to "Content". What you have so far is causing the SelectedValue to be a ComboBoxItem rather than the values that they hold. By setting SelectedValuePath to "Content", you say that you actually want the SelectedValue to be extracted from the Content property of the ComboBoxItems. In summary, this will work:
-Jason Fauchelle |
|
|
Thanks to this last solution you gave, it finally works. Thank you Jason |
|