C# 从ItemsSource同步生成的项目
我正在寻找一种简单的方法来同步由ItemsControl生成的文本大小(按钮内容) 我正在使用以下Xaml代码:C# 从ItemsSource同步生成的项目,c#,wpf,itemssource,C#,Wpf,Itemssource,我正在寻找一种简单的方法来同步由ItemsControl生成的文本大小(按钮内容) 我正在使用以下Xaml代码: <ItemsControl ItemsSource="{Binding UseCases}"> <ItemsControl.ItemsPanel> <ItemsPanelTemplate> <WrapPanel /> </ItemsPanelTemplate> </ItemsControl.Items
<ItemsControl ItemsSource="{Binding UseCases}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel />
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button Content="{Binding DisplayName}" Width="200" Height="200">
<Button.ContentTemplate>
<DataTemplate>
<Viewbox>
<ContentPresenter Content="{Binding}" />
</Viewbox>
</DataTemplate>
</Button.ContentTemplate>
</Button>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
我想使按钮上的文本尽可能大,这已经起作用了。但是由于文本长度不同,每个按钮的文本大小也不同,这看起来很奇怪。
是否有一种简单的方法告诉Viewbox(或任何其他方法)获取最小文本的大小并将其用于每个按钮?要限制文本大小,只需使用填充: 处理文本溢出是一个复杂的部分。出于某种原因(罪魁祸首是-ButtonChrome),按钮不会接受“TextBlock.TextTrimmingProperty”附加属性,但是AttachedProperty机制是专为此类情况设计的),这给您留下了两个选项: