是否可以将WrapPanel中所有TextBlocks的宽度调整为WrapPanel中最大TextBlock的大小?最终结果应该是包含"Some data"的控件的宽度与包含"比以前更多的数据"的控件的宽度相同.我已经附上我的初始代码作为起点.我使用字符串作为示例,但集合数据和模板可以是任何东西,所以我不能依赖字符串的长度.
<Window x:Class="WpfApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:System="clr-namespace:System;assembly=mscorlib"
xmlns:Collections="clr-namespace:System.Collections;assembly=mscorlib"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Window.Resources>
<Collections:ArrayList x:Key="data">
<System:String>Some data</System:String>
<System:String>Some more data</System:String>
<System:String>Even more data than before</System:String>
</Collections:ArrayList>
</Window.Resources>
<ItemsControl ItemsSource="{StaticResource data}">
<ItemsControl.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel></WrapPanel>
</ItemsPanelTemplate>
</ItemsControl.ItemsPanel>
<ItemsControl.ItemTemplate>
<DataTemplate>
<Border Margin="5" BorderThickness="1" BorderBrush="Black">
<TextBlock Text="{Binding}"></TextBlock>
</Border>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Window>
Run Code Online (Sandbox Code Playgroud)
以及所需输出的图像:
我正在尝试制作自定义窗口样式。目标是创建一个模板,供我的应用程序中的每个窗口使用。模板包含工具栏,标题和“窗口将使用的区域”。问题是:使用样式时,我无法再添加网格和控制。
应用程式
<Style x:Key="CustomWindowStyle" TargetType="{x:Type Window}">
<Setter Property="WindowStyle" Value="None"/>
<Setter Property="AllowsTransparency" Value="True"/>
<Setter Property="ResizeMode" Value="NoResize"/>
<Setter Property="Background" Value="MintCream"/>
<Setter Property="BorderBrush" Value="#0046E7"/>
<Setter Property="BorderThickness" Value="2"/>
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type Window}">
<Grid Background="{TemplateBinding Background}">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition/>
<ColumnDefinition Width="Auto"/>
</Grid.ColumnDefinitions>
<StackPanel Grid.ColumnSpan="2">
<TextBlock TextAlignment="Center"
Margin="0 10 0 0"
FontSize="22"
FontWeight="DemiBold"
Foreground="RoyalBlue"
Text="{TemplateBinding Title}"/>
</StackPanel>
<StackPanel Grid.Row="0" Grid.Column="1"
Orientation="Horizontal"
HorizontalAlignment="Stretch"
VerticalAlignment="Center"
Margin="0 10 15 0">
<Button Style="{StaticResource MinimizeButtonStyle}"
Width="25"
Height="22"
Margin="0 0 10 0"/>
<Button Style="{StaticResource CloseButtonStyle}"
Width="25" …
Run Code Online (Sandbox Code Playgroud) 如果值大于0,我需要连接多列的值.
例:
Video 1
Internet 0
Phone 3
Security 0
Basic 1
Run Code Online (Sandbox Code Playgroud)
所以最终的价值就是 1 Video|3 Phone|1 Basic|
有没有比写代码更好的方法来做到这一点:
Case When Video > 0 and Internet+Phone+Security+Basic < 0 Then Video + ' Video|'
When Video > 0 and Internet > 0 and Phone+Security+Basic < 0 Then Video + ' Video|' + Internet + ' Internet|'
When Video > 0 and Phone > 0 and Internet+Security+Basic < 0 Then Video + ' Video|' + Phone + ' Phone|'
Run Code Online (Sandbox Code Playgroud)
等等,直到考虑到每个组合.