我想进度条上同步显示百分比。
{Binding ElementName=Progress,Path=Value}
这样只有数字,我想加上%
同样的绑定,为什么Label不显示格式化? 而TextBox可以。这种标准的不统一,真坑人。
发现StringFormat只能对字符串进行操作,而Label的Content是Object类型的。
方法:
<Label Content="{Binding Path=Value,ElementName=Progress}" ContentStringFormat=" {0}%" Grid.Row="0" Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="48"/>
<Window x:Class="WpfM20UpdateFW.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:local="clr-namespace:WpfM20UpdateFW"
mc:Ignorable="d"
Title="M20 Update Firmware V1.0" Height="450" Width="800" Closed="Window_Closed">
<Grid>
<Grid ShowGridLines="false" MinWidth="20" FocusManager.FocusedElement="{Binding ElementName=download}">
<Grid.RowDefinitions>
<RowDefinition Height="0.2*"></RowDefinition>
<RowDefinition Height="0.8*"></RowDefinition>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="0.2*"></ColumnDefinition>
<ColumnDefinition Width="0.8*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Button x:Name="download" Grid.Row="0" Grid.Column="0" Click="Button_Click" >Download FW</Button>
<ProgressBar x:Name="Progress" Grid.Row="0" Grid.Column="1" />
<Label Content="{Binding Path=Value,ElementName=Progress}" ContentStringFormat=" {0}%" Grid.Row="0" Grid.Column="1" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="48"/>
<TextBox x:Name="logText" Text="{Binding Value,StringFormat={}{0}%, ElementName=Progress }" Grid.Row="1" Grid.ColumnSpan="2" VerticalScrollBarVisibility="Auto" HorizontalScrollBarVisibility="Auto" AcceptsReturn="True" IsReadOnly="True" />
</Grid>
</Grid>
</Window>
想加个快捷键的 (&)用不了?报错。
&转为& 不起作用?
用这个WPFの三种方式实现快捷键 - 走看看 没有winform方便。