设置数据模板的样式以适合 silverlight datgrid 列标题
我在 xaml 页面中有一个带 datatemplate 的样式,如下所示。
<
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 列标题?那么如何才能做到这一点呢?
否则如何拉伸内容模板以填充数据网格列标题的整个空间
i have a style with datatemplate in xaml page as shown below .
<
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>
this style would be applied to the silverlight datgrid column header style.
now i want the stackpanel inside the template to be same as the height and width of the
silverlight datgrid column header ? so how can that be done?
else how to stretch the content template to fill the whole space of the datagrid column header
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您是否尝试过将 StackPanel 的水平和垂直对齐属性设置为拉伸?您根本不需要绑定到父容器的 Width 和 Height 属性。
如果将 StackPanel 设置为拉伸不起作用,只需将堆栈面板包裹在边框中即可。请参阅下面的代码:
Have you tried setting the StackPanel's horizontal and vertical alignment properties to stretch? You shouldn't need to bind to the Width and Height properties of the parent container at all.
If setting the StackPanel to stretch that doesn't work, simply wrap the stack panel in a Border and you will be golden. See the code below: