• <tfoot id='GrWV7'></tfoot>
      <bdo id='GrWV7'></bdo><ul id='GrWV7'></ul>
    <i id='GrWV7'><tr id='GrWV7'><dt id='GrWV7'><q id='GrWV7'><span id='GrWV7'><b id='GrWV7'><form id='GrWV7'><ins id='GrWV7'></ins><ul id='GrWV7'></ul><sub id='GrWV7'></sub></form><legend id='GrWV7'></legend><bdo id='GrWV7'><pre id='GrWV7'><center id='GrWV7'></center></pre></bdo></b><th id='GrWV7'></th></span></q></dt></tr></i><div id='GrWV7'><tfoot id='GrWV7'></tfoot><dl id='GrWV7'><fieldset id='GrWV7'></fieldset></dl></div>

        <small id='GrWV7'></small><noframes id='GrWV7'>

        <legend id='GrWV7'><style id='GrWV7'><dir id='GrWV7'><q id='GrWV7'></q></dir></style></legend>
      1. 将 ListBoxItem IsSelected 触发器传播到子控件

        Propagate ListBoxItem IsSelected trigger to child control(将 ListBoxItem IsSelected 触发器传播到子控件)

                <tbody id='9DEsK'></tbody>

              <tfoot id='9DEsK'></tfoot>
              <i id='9DEsK'><tr id='9DEsK'><dt id='9DEsK'><q id='9DEsK'><span id='9DEsK'><b id='9DEsK'><form id='9DEsK'><ins id='9DEsK'></ins><ul id='9DEsK'></ul><sub id='9DEsK'></sub></form><legend id='9DEsK'></legend><bdo id='9DEsK'><pre id='9DEsK'><center id='9DEsK'></center></pre></bdo></b><th id='9DEsK'></th></span></q></dt></tr></i><div id='9DEsK'><tfoot id='9DEsK'></tfoot><dl id='9DEsK'><fieldset id='9DEsK'></fieldset></dl></div>
            1. <small id='9DEsK'></small><noframes id='9DEsK'>

              <legend id='9DEsK'><style id='9DEsK'><dir id='9DEsK'><q id='9DEsK'></q></dir></style></legend>
                <bdo id='9DEsK'></bdo><ul id='9DEsK'></ul>

                • 本文介绍了将 ListBoxItem IsSelected 触发器传播到子控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我正在开发一个带有自可拆卸 ListBoxItem 的 CheckedListBox.问题是只有当用户点击 CheckBox 区域时才会检查项目,这有点尴尬.

                  I'm developing a CheckedListBox with self removable ListBoxItems. The problem is that an item only gets checked if the user clicks on the CheckBox area, which is kind of awkward.

                  如何创建 ListBoxItem 触发器 (IsSelected) 以检查DataSourced"ListBox 上的复选框?例如:

                  How do I create ListBoxItem triggers (IsSelected) to check the checkboxes on a "DataSourced" ListBox? Eg:

                  以下是我的控件(为简洁起见,所有其他代码均已省略):

                  Below is my control (all other code have been omitted for brevity):

                  <ListBox x:Name="executors" ItemsSource="{Binding Executors}" HorizontalAlignment="Left" Height="121" Margin="23,19,0,0" VerticalAlignment="Top" Width="362">
                      <ListBox.ItemContainerStyle>
                          <Style TargetType="ListBoxItem">
                              <Setter Property="Height" Value="30" />
                              <Setter Property="Template">
                                  <Setter.Value>
                                      <ControlTemplate TargetType="ListBoxItem">
                                          <Grid>
                                              <Grid.ColumnDefinitions>
                                                  <ColumnDefinition />
                                                  <ColumnDefinition Width="30" />
                                              </Grid.ColumnDefinitions>
                                              <CheckBox Margin="4,8" IsChecked="{Binding Enabled}">
                                                  <ContentPresenter Content="{Binding Description}">
                  
                                                  </ContentPresenter>
                                              </CheckBox>
                                              <Button Command="{Binding DataContext.RemoveExecutorCommand, ElementName=executors}" CommandParameter="{Binding}" Background="White" Height="22" Width="22" Grid.Column="1">
                                                  <Image Source="trash.png" Stretch="Fill" Width="14" Height="14" />
                                              </Button>
                                          </Grid>
                                      </ControlTemplate>
                                  </Setter.Value>
                              </Setter>
                          </Style>
                      </ListBox.ItemContainerStyle>
                  </ListBox>
                  

                  Executors 是 ExecutorObservableCollection,其中 EnabledDescription 作为成员.

                  Executors is a ObservableCollection of Executor which has Enabled and Description as members.

                  推荐答案

                  为了给遇到同样问题的人提供进一步的参考,这里有一个我已经完成的工作片段.我在任何地方都找不到任何工作样本,所以这可能很有用.

                  For further reference for those who come across this same question, here's a working snippet I have done. I couldn't find any working sample anywhere, so this might be of much use.

                  这里的主要思想是将选择事件传播到 CheckBoxes,这听起来工作量太大,或者简单地将 CheckBox 选择区域扩展到适合 ListBoxItem.

                  The main idea here was to either propagate the selection event to the CheckBoxes, which sounds too much of a work, or to simple extend the CheckBox selection area to fit the ListBoxItem.

                  下面是如何实现第二个选项的示例:

                  Below is a sample on how to achieve the second option:

                  <ListBox x:Name="executors" ItemsSource="{Binding Executors}" HorizontalAlignment="Left" Height="121" Margin="23,19,0,0" VerticalAlignment="Top" Width="362" ScrollViewer.VerticalScrollBarVisibility="Visible">
                      <ListBox.ItemContainerStyle>
                          <Style TargetType="ListBoxItem">
                              <Setter Property="Height" Value="30"/>
                              <Setter Property="VerticalContentAlignment" Value="Stretch"/>
                              <Setter Property="Template">
                                  <Setter.Value>
                                      <ControlTemplate TargetType="ListBoxItem">
                                          <Grid>
                                              <Grid.ColumnDefinitions>
                                                  <ColumnDefinition Width="9*"/>
                                                  <ColumnDefinition Width="1*" />
                                              </Grid.ColumnDefinitions>
                                              <CheckBox Content="{Binding Description}" IsChecked="{Binding Enabled}" VerticalContentAlignment="Center" Margin="4,0"/>
                                              <Button Command="{Binding DataContext.RemoveExecutorCommand, ElementName=executors}" CommandParameter="{Binding}" Width="21" Height="21" Background="White" Grid.Column="1">
                                                  <Image Source="trash.png" Stretch="Fill" Width="14" Height="14" />
                                              </Button>
                                          </Grid>
                                      </ControlTemplate>
                                  </Setter.Value>
                              </Setter>
                          </Style>
                      </ListBox.ItemContainerStyle>
                  </ListBox>
                  

                  这应该产生以下内容:

                  这篇关于将 ListBoxItem IsSelected 触发器传播到子控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  Populate ListBox with a IEnumrable on another thread (winforms)(在另一个线程(winforms)上使用 IEnumrable 填充 ListBox)
                  listbox selected item give me quot; System.Data.DataRowViewquot; , C# winforms(列表框选择的项目给我quot;System.Data.DataRowView, C# Winforms)
                  Cannot remove items from ListBox(无法从列表框中删除项目)
                  Preventing ListBox scrolling to top when updated(更新时防止列表框滚动到顶部)
                  Drag and drop from list to canvas on windows phone with MVVM(使用 MVVM 在 Windows 手机上从列表拖放到画布)
                  Deselection on a WPF listbox with extended selection mode(具有扩展选择模式的 WPF 列表框上的取消选择)
                  <legend id='pyGKd'><style id='pyGKd'><dir id='pyGKd'><q id='pyGKd'></q></dir></style></legend>
                  • <i id='pyGKd'><tr id='pyGKd'><dt id='pyGKd'><q id='pyGKd'><span id='pyGKd'><b id='pyGKd'><form id='pyGKd'><ins id='pyGKd'></ins><ul id='pyGKd'></ul><sub id='pyGKd'></sub></form><legend id='pyGKd'></legend><bdo id='pyGKd'><pre id='pyGKd'><center id='pyGKd'></center></pre></bdo></b><th id='pyGKd'></th></span></q></dt></tr></i><div id='pyGKd'><tfoot id='pyGKd'></tfoot><dl id='pyGKd'><fieldset id='pyGKd'></fieldset></dl></div>
                    <tfoot id='pyGKd'></tfoot>
                        <tbody id='pyGKd'></tbody>
                    1. <small id='pyGKd'></small><noframes id='pyGKd'>

                          <bdo id='pyGKd'></bdo><ul id='pyGKd'></ul>