Note that there are some explanatory texts on larger screens.

plurals
  1. POWPF ComboBox with CheckBox - Collapsed display value
    primarykey
    data
    text
    <p>I have a <code>ComboBox</code> that has an <code>ItemTemplate</code> with a <code>CheckBox</code> in it (read Dropdown CheckBoxList). I basically want to have a separate binding for the text in the combobox (both when an item is selected, and if an item isn't selected). I've <a href="https://stackoverflow.com/a/6606691/861974">tried</a> a <a href="https://stackoverflow.com/a/6506600/861974">few</a> <a href="https://stackoverflow.com/questions/4672867/can-i-use-a-different-template-for-the-selected-item-in-a-wpf-combobox-than-for/4673269#4673269">different</a> <a href="https://stackoverflow.com/a/2277488/861974">methods</a> but either can't seem to get them to work with my setup, or can't find they have some issues. I've even tried a few mixes and matches of them. Usually I find they either don't work when an item isn't specifically selected (which could be possible if the user checks a few boxes then clicks out of the <code>ComboBox</code>), or aren't updating the text properly.</p> <p>My xaml is this (the items of focus are the <code>DataTemplates</code> with the <code>ComboBoxes</code> in them):</p> <pre><code>&lt;UserControl x:Class="BestClient.ucReportViewer" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:BestClient" mc:Ignorable="d" d:DesignHeight="315" d:DesignWidth="388" Background="#FFD7DFEC"&gt; &lt;UserControl.Resources&gt; &lt;DataTemplate x:Key="datetime"&gt; &lt;StackPanel Orientation="Horizontal" Height="35"&gt; &lt;TextBlock Text="{Binding rfName}" Width="100" VerticalAlignment="Center" /&gt; &lt;DatePicker Tag="{Binding rfParameter}" SelectedDate="{Binding rfValues, Mode=TwoWay}" Width="200" VerticalAlignment="Center" /&gt; &lt;/StackPanel&gt; &lt;/DataTemplate&gt; &lt;DataTemplate x:Key="office"&gt; &lt;StackPanel Orientation="Horizontal" Height="35"&gt; &lt;TextBlock Text="{Binding rfName}" Width="100" VerticalAlignment="Center" /&gt; &lt;ComboBox x:Name="officeComboBox" Tag="{Binding rfParameter}" Width="200" ItemsSource="{Binding Path=DataContext.OfficeList, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Mode=TwoWay}" VerticalAlignment="Center"&gt; &lt;ComboBox.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;CheckBox Tag="{Binding id}" IsChecked="{Binding isSelected}" Width="200" Content="{Binding value}" Margin="2" x:Name="CheckBox" Checked="OfficeCheckBox_Checked"/&gt; &lt;/DataTemplate&gt; &lt;/ComboBox.ItemTemplate&gt; &lt;/ComboBox&gt; &lt;/StackPanel&gt; &lt;/DataTemplate&gt; &lt;DataTemplate x:Key="carrier"&gt; &lt;StackPanel Orientation="Horizontal" Height="35"&gt; &lt;TextBlock Text="{Binding rfName}" Width="100" VerticalAlignment="Center" /&gt; &lt;ComboBox Tag="{Binding rfParameter}" Width="200" ItemsSource="{Binding Path=DataContext.CarrierList, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}, Mode=TwoWay}" VerticalAlignment="Center"&gt; &lt;ComboBox.ItemTemplate&gt; &lt;DataTemplate&gt; &lt;StackPanel Orientation="Horizontal"&gt; &lt;CheckBox Tag="{Binding id}" IsChecked="{Binding isSelected}" Width="200" Content="{Binding value}" Margin="2"/&gt; &lt;/StackPanel&gt; &lt;/DataTemplate&gt; &lt;/ComboBox.ItemTemplate&gt; &lt;/ComboBox&gt; &lt;/StackPanel&gt; &lt;/DataTemplate&gt; &lt;DataTemplate x:Key="defaultTemplate"&gt; &lt;StackPanel Orientation="Horizontal" Height="35"&gt; &lt;TextBlock Text="{Binding rfName}" Width="100" VerticalAlignment="Center" /&gt; &lt;TextBox Tag="{Binding rfParameter}" Width="200" VerticalAlignment="Center" /&gt; &lt;/StackPanel&gt; &lt;/DataTemplate&gt; &lt;local:ReportFilterTemplateSelector x:Key="ReportFilterTemplateSelector" /&gt; &lt;/UserControl.Resources&gt; &lt;Grid x:Name="ReportViewer"&gt; &lt;Grid.ColumnDefinitions&gt; &lt;ColumnDefinition Width="1*"/&gt; &lt;ColumnDefinition Width="1*"/&gt; &lt;ColumnDefinition Width="1*"/&gt; &lt;/Grid.ColumnDefinitions&gt; &lt;Grid.RowDefinitions&gt; &lt;RowDefinition Height="45"/&gt; &lt;RowDefinition Height="*"/&gt; &lt;RowDefinition Height="45"/&gt; &lt;/Grid.RowDefinitions&gt; &lt;Viewbox Grid.Row="0" Grid.Column="0"&gt; &lt;TextBlock Margin="10" TextWrapping="Wrap" Text="Select a Report:"/&gt; &lt;/Viewbox&gt; &lt;ComboBox Grid.Column="1" Margin="10" Grid.ColumnSpan="2" ItemsSource="{Binding ReportList}" DisplayMemberPath="Value" SelectedValuePath="Key" SelectedItem="{Binding SelectedReport}" VerticalContentAlignment="Center" /&gt; &lt;ListView x:Name="FilterList" Margin="10,0" Grid.Row="1" Grid.ColumnSpan="3" ItemTemplateSelector="{StaticResource ReportFilterTemplateSelector}" ItemsSource="{Binding reportFilters, Mode=TwoWay}" /&gt; &lt;Button Command="{Binding OpenReport}" Content="Open Report" Grid.Column="2" Margin="10" Grid.Row="2" VerticalAlignment="Stretch"/&gt; &lt;/Grid&gt; &lt;/UserControl&gt; </code></pre> <p>Ideally, I'd like to bind the display text of the combobox with the <code>OfficeListValues</code> method in my ViewModel.</p> <pre><code>{Binding Path=DataContext.OfficeListValues, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}} </code></pre> <p>Any help would be appreciated!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload