[英]Dynamically set Textblock size when Column containing it, is resized
我有一个xceed网格(不确定是否重要),其中一列具有一个具有TextBlock的CellContentTemplate。 而不是将textblock宽度自动设置为文本大小,我希望它成为列的大小。 我允许调整大小,因此这使事情变得有些复杂。 有没有一种方法可以在后面的代码中调整列的大小时动态更改TextBlock的宽度?
编辑:CellContentTemplate
<DataTemplate x:Key="CellTemplate.TaskName">
<StackPanel Orientation="Horizontal">
<TextBlock Tag="{Binding Path=DataContext, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type UserControl}}}">
<TextBlock Text="{Binding Path=Name}" >
<ui:DragDropBinding.DragSource>
<Binding Mode="TwoWay" RelativeSource="{RelativeSource FindAncestor, AncestorType={x:Type XceedProviders:DataGridControlWithSelectedItems}}" Path="BindableSelectedItems" PresentationTraceSources.TraceLevel="High"/>
</ui:DragDropBinding.DragSource>
</TextBlock>
</TextBlock>
</StackPanel>
</DataTemplate>
嗨,这是因为您将TextBlock包含在StackPanel中。 一种简单的解决方法是代替两个TextBlock使用两个Run来绑定两个属性,例如
<DataGridTemplateColumn Header="Name" Width="*" >
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<TextBlock Background="Green">
<Run Text="{Binding Name}"/>
<Run Text="{Binding Rollno}"/>
</TextBlock>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
现在textblock将随着列的宽度扩展。我希望这会有所帮助。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.