Hello,
I have this problem. I have a class named Holds with 2 properties: OriginOrTargetId(type int) and OriginOrTargetName(type string).
I have a Combobox in my xaml file that display the OriginOrTargetName of this object. And I have a Grid with two columns (one of them display the holds, so I have the HoldId (corresponds to the OriginOrTargetId) also on this object).
I need that when I select a value OriginOrTargetName displayed in the combo I need to filter in the grid the correct hold through the OriginOrTargetId.
I also need that at the opening of the page all the holds in the Grid are visible (and it's ok if nothing is selected in the combo or also there is a a default value like "please Select..."). How can I do this? I have an exception of filtering on the OriginOrTargetId and I'm not able to display all the holds when nothing is selected in the combo. Here is my code:
In the XAML I declare:
<Grid Grid.Row="2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" >
...some code to define columns...
<ComboBox Grid.Column="1" Name="NamesDDL" ItemsSource="{Binding YardHolds}"
SelectedItem="{Binding SelectedYardHold, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"
IsEnabled="True"
IsEditable="True" >
<ComboBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center">
<TextBlock Text="{Binding HoldName}"/>
<TextBlock Text="{Binding HoldId}" Visibility="Hidden"/> //I don't know if it is necessary
</StackPanel>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>
</Grid>
In my VIEWMODEL class I have done this:
public CompositeFilterDescriptor FilterDescriptor { get; set; }
public FilterDescriptor HoldFilterDescriptor { get; set; }
public ObservableCollection<TerminalHold> YardHolds { get; set; }
public TerminalHold SelectedYardHold { get; set; }
FilterDescriptor = new CompositeFilterDescriptor
{
LogicalOperator = FilterCompositionLogicalOperator.And
};
HoldFilterDescriptor = new FilterDescriptor("OriginOrTargetId", FilterOperator.IsEqualTo, null);
FilterDescriptor.FilterDescriptors.Add(HoldFilterDescriptor);
private void OnSelectedYardHoldChanged()
{
if (SelectedYardHold == null || SelectedYardHold.Id < 1)
HoldFilterDescriptor.Value = "";
else
HoldFilterDescriptor.Value = SelectedYardHold.HoldId;
}
What am I wrong? I have search everywhere and for now I'm not able to found a solution!
Thank you