u盘format命令无效-()

来源:191路由网 2022-11-26 17:07:32

u盘format命令无效 ()

在WPF程序设计时,若使用Label控件绑定数据后StringFormat进行格式化显示时发现设定的StringFormat无效,但TextBlock控件中使用StringFormat显示正常,导致Label控件StringFormat失败的根本原因在于Label控件的Content属性是一个object对象,Binding.StringFormat仅作用于string类型属性。

若需要对Label的Content进行格式化显示,需要使用ContentStringFormat属性来进行单独设置,示例如下:

<Label Content="{Binding Path=MaxLevelofInvestment}" ContentStringFormat="Amount is {0}" />示例程序

XAML代码:

<Window x:Class="WpfApp5.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:WpfApp5" mc:Ignorable="d" Title="MainWindow" Height="450" Width="800" FontSize="24"> <Window.Resources> <local:DataConext_MainWindow x:Key="DC"/> </Window.Resources> <Grid DataContext="{StaticResource DC}"> <Grid.RowDefinitions> <RowDefinition/> <RowDefinition/> <RowDefinition/> <RowDefinition/> </Grid.RowDefinitions> <TextBlock Grid.Row="0" Text="{Binding Width, StringFormat={}{0:F3} }"/> <TextBlock Grid.Row="1" Text="{Binding Height, StringFormat={}{0:F2} }"/> <Label Grid.Row="2" Content="{Binding Width}" ContentStringFormat="{}{0:F3}"/> <Button Grid.Row="3" Content="Modify" Click="Button_Click"/> </Grid></Window>


cs代码


using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using System.Windows;using System.Windows.Controls;using System.Windows.Data;using System.Windows.Documents;using System.Windows.Input;using System.Windows.Media;using System.Windows.Media.Imaging;using System.Windows.Navigation;using System.Windows.Shapes;using SAUtil;namespace WpfApp5{ /// <summary> /// Interaction logic for MainWindow.xaml /// </summary> public partial class MainWindow : Window { public MainWindow() { InitializeComponent(); } private void Button_Click(object sender, RoutedEventArgs e) { var dc = Resources["DC"] as DataConext_MainWindow; dc.Height = 12.34556666f; dc.Width = 12.34556666; } } public class DataConext_MainWindow : ValidatableModel { #region Height private float _Height = 0; public float Height { get { return _Height; } set { if (_Height == value) return; _Height = value; RaisePropertyChanged(); } } #endregion #region Width private double _Width = 0; public double Width { get { return _Width; } set { if (_Width == value) return; _Width = value; RaisePropertyChanged(); } } #endregion }}


运行效果

运行效果


参考资料

https://rotadev.com/wpf-stringformat-on-label-content-dev/

点击展开全文

相关阅读

u盘format命令无效-()

u盘format命令无效()在WPF程序设计时,若使用Label控件绑定数据后StringFormat进行格式化显示时发现设定的StringFormat无效,但TextBlock控件中使用StringFormat显示正常,导致Label控件StringFormat失败的根本原因在于Label控件的Content属性是一个object对象,Binding.Str...

2022-11-26

有东西u盘系统错误怎么办-(有东西u盘系统错误怎么办)

有东西u盘系统错误怎么办(有东西u盘系统错误怎么办)U盘在我们的日常生活,工作中出现,经常用来储存一些重要的文件资料,但是不可避免的由于错误操作,导致计算机不能识别U盘。这样U盘的重要的数据就有可能是会因此而...

2022-11-26

2017电脑重装系统-(最新电脑重装系统)

2017电脑重装系统(最新电脑重装系统)电脑如何重装系统,安装操作系统的方法很多可分为u盘安装、硬盘安装、光盘安装、ghost还原这几种,不同的安装类型在安装前的准备工作稍有不同而且安装的时间也会不一样,但安装的流程都基...

2022-11-26

win7被锁定主页-(win7首页被锁定)

win7被锁定主页(win7首页被锁定)Win7系统任务管理器被锁定怎么办?Win7系统任务管理器无法打开被锁定该如何解决?下面就给大家分享Win7系统任务管理器被锁定的解决方法。解决方法:1.登录到系统桌面,使用组合快捷键win键+r键打开运行窗口,在打开的运行窗口中输入“gpedit.msc”回车确认,打开本地组策略编辑器。如下图所示2.在...

2022-11-26

u盘如何重装win764位系统下载-()

u盘如何重装win764位系统下载()U盘重装Windows系统需要做的准备1、一个已经制作完成PE启动盘的U盘。2、下载Windows系统镜像文件。大家随便下载什么系统都行,xp,win7,win10重装步骤都一样的,选择你自己想下载的系就行了。接下来,我们会以64位的win...

2022-11-26

191路由网 - 192.168.1.1,192.168.0.1无线路由器设置教程

版权声明:本站的文章和图片来自互联网收集,仅做分享之用如有侵权请联系站长,我们将在24小时内删除