ObservableCollectionがあり、このObservableCollectionをリストボックス内のアイテムと比較したい場合、プロジェクトの実行後にトグルボタンのリストを埋めるリストボックスがあります.ObservableCollectionのアイテムがリストボックスに存在する場合、このアイテムを作りたいです(トグルボタン) チェック済み、
私はそれをやろうとしましたが、プロジェクトの実行後にトグルボタンのリストが表示されるため、コードビハインドでトグルボタンにアクセスできません。
これが私のリストボックスコードです:
<ListBox x:Name="lbname" ItemsSource="{Binding source}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<ToggleButton x:Name="btnitem" Content="{Binding Name}"/>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ListBox>
と私の observableCollection :
IQueryable<items> query = _context.items;
ocitems = new ObservableCollection<items>(query);
要するに、ObservableCollectionアイテムをリストボックス(ボタン)と比較し、アイテムがリストボックスに存在する場合、アイテムを表すトグルボタンをチェックするにはどうすればよいですか?
これが明確であることを願っています。
- - - - - - - - - - - - - - - - - - - - - もっと詳しく
選択した項目の選択肢を表示するこのリスト ボックスがあります。この listBox は ObservableCollection "ocSelectedChoice" で満たされています。
<ListBox x:Name="lbChoices" ItemsSource="{Binding ocSelectedChoice}" DisplayMemberPath="ChoiceName" HorizontalAlignment="Left" Height="165" VerticalAlignment="Top" Width="186" Margin="567,50,0,0" BorderBrush="#FFC1C1C1" Background="#FFE3E3E3" SelectionMode="Extended">
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="Height" Value="30"/>
<Setter Property="Background" Value="#FFc4d0df"/>
<Setter Property="BorderBrush" Value="#FFC1C1C1"/>
<Setter Property="BorderThickness" Value="0.8"/>
</Style>
</ListBox.ItemContainerStyle>
</ListBox>
このアイテムの選択肢を変更したい場合は、編集ボタンを押すと、利用可能なすべての選択肢の ObservableCollection で満たされたリストボックスを持つウィンドウが表示されます。写真を参照してください。 ) 選択肢ウィンドウで:
<ItemsControl x:Name="icItemGroup" ItemsSource="{Binding PagedSource, ElementName=rdpChoices}" Margin="26,79,0,0" FontWeight="Bold" HorizontalAlignment="Left" Width="506" Height="210" VerticalAlignment="Top" >
<!-- ItemsPanelTemplate -->
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<UniformGrid Columns="4" HorizontalAlignment="left" />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<!-- ItemTemplate -->
<ItemsControl.ItemTemplate>
<DataTemplate>
<ToggleButton x:Name="tbtnChoices" HorizontalAlignment="Left" VerticalAlignment="Top" FontFamily="tahoma" FontSize="12" Height="45" Width="120" FontWeight="Normal" Margin="0,0,0,5" Background="#FFE8E8E8" BorderBrush="#FFC1C1C1" Foreground="#FF6A6A6A"
Content="{Binding ChoiceName}" TabIndex="{Binding ChoicesID}" Click="tbtnChoices_Click">
<ToggleButton.IsChecked>
<MultiBinding Converter="{StaticResource Choices}">
<Binding Path="ocChoice" RelativeSource="{RelativeSource AncestorType={x:Type Window}}"/>
</MultiBinding>
</ToggleButton.IsChecked>
</ToggleButton>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
コンバーター:
public class ChoicesConverter : IMultiValueConverter
{
public object Convert(object[] values, Type targetType, object parameter,
System.Globalization.CultureInfo culture)
{
Choice _choice = values[0] as Choice;
ObservableCollection<Choice> ocChoices = values[1] as ObservableCollection<Choice>;
return ocChoices.Contains(_choice);
}
public object[] ConvertBack(object value, Type[] targetTypes, object parameter,
System.Globalization.CultureInfo culture)
{
return null;
}
}
私はこれを作ろうとしましたが、申し訳ありませんが、まだ不明な点があります。私のプロジェクトにとって重要であるため、この問題の解決を手伝ってください。