|
First of all you are correct they are bound to different properties of the Parameter object.
My question is though, that I am binding the ComboBox to a Collection of Classes, and the Parameter object as a property which is a the same class, so I would think that the SelectedValue should be able to bind directly to that Value, since they are of the same type. It is just instead of it being a string object, is of another type. I tried using:
SelectedValue="{Binding SelectedParameter.Name.ParameterDisplayName, Mode=TwoWay}"
but then the actual property doesn't get set correctly.
How can I set that combobox to be the correct item then?
|
|
|
|
|
Give this a try,
<ComboBox x:Name="cboParameterName"
VerticalAlignment="Center"
IsSynchronizedWithCurrentItem="True"
TabIndex="10"
Grid.Column="1"
Grid.ColumnSpan="4"
ItemsSource="{Binding Path=ParameterNameCollection}"
SelectedValue="{Binding Path=SelectedParameter.Name.ParameterDisplayName}"
SelectedValuePath="Name.ParameterDisplayName"
Style="{DynamicResource BaseComboBox}">
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name.ParameterDisplayName}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
Note: Added SelectedValuePath and changed the DataTemplate
(fingers crossed ,X,, )
|
|
|
|
|
I have been playing with using the SelectedIndex. And it seems to work, at least for now, the problem that I foresee is that I will have to go through the Combobox source to get the index each time, in the event that the Index would change, either by addition or substraction of Metadata.
What are your thoughts on that?
|
|
|
|
|
BTW, I tried your suggestion and the first problem was that the combobox wasn't showing what was loaded, the second problem was that the parameter.name wasn't being set either
|
|
|
|
|
babongita wrote: combobox wasn't showing what was loaded
What did it show then ? Was there any value in the SelectedParameter, since that is what is driving the SelectedItem.
babongita wrote: parameter.name wasn't being set either
Why is this a combobox problem ?? Combobox is reading this value, someone has to be setting it ??
Did you check your output window? It would be logging DataBinding errors.
|
|
|
|
|
I didn't check the output window to see what was happening. When I hit the dropdown on the combo I couldn't see anything in it, but the itemsource had the values.
But digging into the SelectedIndex seems to be the way to go here, it is performing as expected. But like I said, I will need to get the Index each time the screen loads, since the Index may change, not often but enough that I can't rely on that being the same
I guess I could create a converter for that couldn't I, then it would be more of an "automated" thing, right?
|
|
|
|
|
babongita wrote: I didn't check the output window to see what was happening. When I hit the dropdown on the combo I couldn't see anything in it, but the itemsource had the values.
That is because some binding is failing. If you check the Output window it would clearly mention which binding is failing and why. The comboox SelectedItem is being driven by the SelectedParamter Dependency Property. Check what value it has. If it is null(or the Name property), then the combobox cannot do anything.
babongita wrote: But digging into the SelectedIndex seems to be the way to go here, it is performing as expected. But like I said, I will need to get the Index each time the screen loads, since the Index may change, not often but enough that I can't rely on that being the same
So, if I understand you correct, you will search for the objects in the comboxbox and set the combobox SelectedIndex to it ? Would this be on the SelectionChange of your listviewm - where you would get the listview's selected item and search that in the combobox ?
babongita wrote: I could create a converter
Well, that seems to be a *workaround*. I would fix the damn databinding issue
I think you could look at this as an option,
<ComboBox x:Name="cboParameterName"
VerticalAlignment="Center"
IsSynchronizedWithCurrentItem="True"
TabIndex="10"
Grid.Column="1"
Grid.ColumnSpan="4"
ItemsSource="{Binding Path=ParameterNameCollection}"
SelectedItem="{Binding Path=SelectedParameter}"
Style="{DynamicResource BaseComboBox}"
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name.ParameterDisplayName}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
One more thing is, since you are driving this combobox from a listview, why don't you bind the ListView's SelectedItem to the combobox's SelectedItem ,
<ComboBox x:Name="cboParameterName"
VerticalAlignment="Center"
IsSynchronizedWithCurrentItem="True"
TabIndex="10"
Grid.Column="1"
Grid.ColumnSpan="4"
ItemsSource="{Binding Path=ParameterNameCollection}"
SelectedItem="{Binding ElementName="yourListView" Path=SelectedItem}"
Style="{DynamicResource BaseComboBox}"
<ComboBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding Name.ParameterDisplayName}"/>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
Have fun
|
|
|
|
|
I was thinking about binding to the ListView but the problem I had was that the user has the option to Add/Edit/Remove (all buttons on the view) a parameter, and I couldn't figure out how to add a new parameter and still have it be bound. Does that make sense? Can I email you offline? I would like to discuss this offline with some screen shots of what I am trying to duplicate.
modified on Friday, March 6, 2009 12:46 PM
|
|
|
|
|
I do not think it is a good idea to share yur email id in public.
|
|
|
|
|
OK well I modified that post. But is it possible that we could continue this offline?
|
|
|
|
|
I am a dedicated member, always available at CP
|
|
|
|
|
OK I am going back through now and trying you recommendations and this is the error that I am getting in the Output window
System.Windows.Data Error: 39 : BindingExpression path error: 'Name' property not found on 'object' ''ParameterName' (HashCode=62178992)'. BindingExpression:Path=Name.ParameterDisplayName; DataItem='ParameterName' (HashCode=62178992); target element is 'ComboBox' (Name='cboParameterName'); target property is 'NoTarget' (type 'Object')
|
|
|
|
|
OK I have finally figured it out, but it really is a different work around. Or at least it seems like it. If instead of creating the ParameterName objects with all of the properties associated with it, if I only create a collection of strings and then bind them to the dropdown box then I can make the binding work. But it is not the object itself it is only one piece of the object.
|
|
|
|
|
I am suprised it does not work while binding to the the string property of the object. Well, if it is so, you can use a converter taking the object and returning a string for it rather than having to have a string collection. Which particular binding was failing, the one in the combobox DataTemplate ? I still feel that your data was not being populated correct.
|
|
|
|
|
babongita wrote: but any item bound to an object (in this case a Combobox) that attribute is not populated
The above statement confuses me. It says any item bound to the object is not populated. You mean never or again just when you do something from code ?
|
|
|
|
|
OK, There is a listbox below, which is bound to Collection of Parameters(this is a class, not what you would typically think of when you think parameters), then there is a "view" above it which shows the "detail" (attributes) of the SelectedItem in the listbox. All of the TextBoxes or the CheckBoxes show the "detail" (attributes) correctly. But when the "detail" (attribute) is an item in a Combobox the item doesn't show in the Combobox even though it is bound to that "detail"(attribute). The combobox is populated with all of the possible selections, but the SelectedItem, isn't shown in that combobox.
|
|
|
|
|
I think that you are missing the ElementName in the ItemsSource Binding. In this case the ElementName is the x:Name of your window or UserControl.
<combobox x:name="cboParameterName" xmlns:x="#unknown">
IsSynchronizedWithCurrentItem="True"
TabIndex="10"
Grid.Column="1"
Grid.ColumnSpan="4"
ItemsSource="{Binding Path=ParameterNameCollection, ElementName=UserControl, Mode=Default}"
SelectedValue="{Binding SelectedParameter.Name}"
Style="{DynamicResource BaseComboBox}">
<combobox.itemtemplate>
<datatemplate>
<textblock text="{Binding ParameterDisplayName}">
|
|
|
|
|
No, he is using DataContext of the parent implicitly.
|
|
|
|
|
on a side note this happens with all of the comboboxes, but I have them all coded the same so I have the same issue.
|
|
|
|
|
|
When are you calling OnMouseUp ? Taking a guess, I think you do not need it. Looks like OnMouseDown and OnMouseMove are doing what you want ??
|
|
|
|
|
|
Prajeesh wrote: StartPoint = Args.GetPosition(PhotoBox);
In the MoveDown event, what is PhotoBox? shouldn't it be DrawingCanvas ?
I did the same thing you are doing, on the MouseMove and MouseLeftButtonDown event of the Canvas, and I never got any extra lines.
|
|
|
|
|
|
private void OnMouseMove(object Sender, MouseEventArgs Args)
{
if (Args.LeftButton == MouseButtonState.Pressed)
{
EndPoint = Args.GetPosition(DrawingCanvas);
DrawLine(StartPoint, EndPoint, DrawingCanvas);
//do not reset the startpoint
//StartPoint = EndPoint;
}
}
And in your DrawLine method, delete the old line before adding the new line.
|
|
|
|