【问题标题】:styling the datatemplate to fit silverlight datgrid column header设置数据模板以适合 silverlight datagrid 列标题
【发布时间】:2011-05-04 07:50:19
【问题描述】:

我在 xaml 页面中有一个带有数据模板的样式,如下所示。

<

    Style x:Name="mytemplate" x:Key="mytemplate"  xmlns:dataprimitives="clr-namespace:System.Windows.Controls.Primitives;assembly=System.Windows.Controls.Data"
                                TargetType="dataprimitives:DataGridColumnHeader">
                <Setter Property="ContentTemplate" >
                    <Setter.Value>
                        <DataTemplate>
                            <StackPanel Background="Aqua" Height="{Binding this.DataGridColumnHeader.Height}" Width="{Binding this.DataGridColumnHeaderWidth}" >
       <TextBlock Text="{Binding}"   HorizontalAlignment="Center" FontWeight="Black" ></TextBlock>
                                 <TextBox x:Name="{Binding}" Padding="0,-1,0,0"  HorizontalAlignment="Stretch" Width="100" Height="20" KeyDown="txtfilterBox_KeyDown" LostFocus="txtfilterBox_LostFocus" />
                            </StackPanel>
                        </DataTemplate>
                    </Setter.Value>
                </Setter>
            </Style>

此样式将应用于 silverlight datgrid 列标题样式。 现在我希望模板内的堆栈面板与模板的高度和宽度相同 silverlight datgrid 列标题?那怎么办呢?

否则如何拉伸内容模板以填充数据网格列标题的整个空间

【问题讨论】:

    标签: silverlight datagrid datagridtemplatecolumn


    【解决方案1】:

    您是否尝试过将 StackPanel 的水平和垂直对齐属性设置为拉伸?您根本不需要绑定到父容器的 Width 和 Height 属性。

    如果将 StackPanel 设置为拉伸不起作用,只需将堆栈面板包裹在 Border 中即可。请看下面的代码:

    <Style x:Name="mytemplate" x:Key="mytemplate"  xmlns:dataprimitives="clr-namespace:System.Windows.Controls.Primitives;assembly=System.Windows.Controls.Data"
                                        TargetType="dataprimitives:DataGridColumnHeader">
                        <Setter Property="ContentTemplate" >
                            <Setter.Value>
                                <DataTemplate>
                        <Border Background="Aqua" VerticalAlignment="Stretch" HorizontalAlignment="Stretch">
                                        <StackPanel>
                              <TextBlock Text="{Binding}"   HorizontalAlignment="Center" FontWeight="Black" ></TextBlock>
                                          <TextBox x:Name="{Binding}" Padding="0,-1,0,0"  HorizontalAlignment="Stretch" Width="100" Height="20" KeyDown="txtfilterBox_KeyDown" LostFocus="txtfilterBox_LostFocus" />
                                        </StackPanel>
                        </Border>
                                </DataTemplate>
                            </Setter.Value>
                        </Setter>
                    </Style>
    

    【讨论】:

      猜你喜欢
      • 2010-09-14
      • 1970-01-01
      • 1970-01-01
      • 2011-09-14
      • 2011-04-18
      • 2011-05-13
      • 2023-03-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多