【问题标题】:Binding Errors in DataTemplated ListBoxItemsDataTemplated ListBoxItems 中的绑定错误
【发布时间】:2011-03-28 18:45:58
【问题描述】:

目前我有一个用户控件,其中包含其他视觉元素用户控件的列表框;其中(对于这种特殊情况)已被数据模板化。

<Grid>
    <ListBox ItemSource="{Binding Path=UserControlCollection}">
        <ListBox.ItemTemplate>
             <DataTemplate>
                  <StackPanel Orientation="Horizontal">
                      <ContentPresenter Content="{Binding}"/>
                      <Button/>
                  </StackPanel>
             </DataTemplate>
        </ListBox.ItemTemplate>
    </ListBox>
</Grid>

问题是我有 This Issue. 并且由于数据模板,我似乎无法找到纠正样式问题的方法。

任何帮助将不胜感激。

【问题讨论】:

    标签: c# wpf xaml listbox datatemplate


    【解决方案1】:

    我发现通过覆盖ListBoxItem 的水平内容对齐和垂直内容对齐,我能够纠正这个问题。

     <ListBox.ItemContainerStyle>
         <Style TargetType="ListBoxItem">
             <Setter Property="HorizontalContentAlignment" Value="Stretch"/>
             <Setter Property="VerticalContentAlignment" Value="Stretch"/>
         </Style>
     </ListBox.ItemContainerStyle>
    

    我还发现更改为列表视图很有帮助,但确实存在问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-07-26
      • 1970-01-01
      • 1970-01-01
      • 2015-08-10
      • 2023-03-19
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多