WPF binding Label不显示格式化ContentStringFormat的用法,(&D)用不了

我想进度条上同步显示百分比。

{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>

想加个快捷键的  (&)用不了?报错。

&转为&amp;   不起作用?

用这个WPFの三种方式实现快捷键 - 走看看  没有winform方便。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

小黄人软件

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值