当前位置: 首页 > news >正文

网站开发毕业设计指导记录网站加盟代理

网站开发毕业设计指导记录,网站加盟代理,企业网站的运营如何做,专门找人做软件的网站在基本绑定中#xff0c;信息从源到目标的传递过程中没有任何变化。这看起来是符合逻辑的#xff0c;但我们并不总是希望出现这种行为。通常#xff0c;数据源使用的是低级表达方式#xff0c;我们可能不希望直接在用户界面使用这种低级表达方式。WPF提供了两个工具#x…在基本绑定中信息从源到目标的传递过程中没有任何变化。这看起来是符合逻辑的但我们并不总是希望出现这种行为。通常数据源使用的是低级表达方式我们可能不希望直接在用户界面使用这种低级表达方式。WPF提供了两个工具来进行数据转换 字符串格式化 通过设置 Binding.StringFormat 属性对文本形式的数据进行转换——例如包含日期和数字的字符串。 值转换器 该功能更强大使用该功能可以将任意类型的源数据转换为任意类型的对象表示然后可以传递到关联的控件。 使用StringFormat属性 TextBlock Grid.Row0 Grid.Column0 Text{Binding PathPrice, StringFormatConvertDirectly:{0:C}}/TextBlock TextBox Grid.Row0 Grid.Column1 Text{Binding PathPrice, StringFormat{}{0:C}}/TextBox TextBox Grid.Row2 Grid.Column1 Text{Binding PathOrderDate, StringFormat{}{0:s}}/TextBox 可以看到后面两个StringFormat属性以花括号 {} 开头完整值是 {}{0:C}而不是 {0:C}第一个则只有 {0:C}这是因为在StringFormat 值以花括号开头时需要 {} 转义序列。 使用值转换器 为创建子转换器需要执行以下四个步骤 1、创建一个实现IValueConverter接口的类 2、为该类声明添加ValueConversion特性并指定目标数据类型 3、实现Convert()方法该方法将数据从原来的格式转换为显示的格式 4、实现ConvertBack()方法该方法执行反向变换将值从显示格式转换为原格式 [ValueConversion(typeof(decimal), typeof(string))] public class PriceConverter : IValueConverter {public object Convert(object value, Type targetType, object parameter, CultureInfo culture){decimal price (decimal)value;return price.ToString(C, culture);}public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture){string price (string)value;if (decimal.TryParse(price, System.Globalization.NumberStyles.Any, culture, out decimal result)){return result;}return value;} } 要使用这个转换器可以将其添加到页面的资源下然后使用 Binding.Converter 指定。 WindowWindow.Resourceslocal:PriceConverter x:KeypriceConverter/local:PriceToBackgroundConverter x:KeypriceToBackgroundConverter MinimumPriceToHighlight100 DefaultBrush{x:Null} HighlightBrushOrange/local:ImagePathConverter x:KeyimagePathConverter/local:MultiValueConverter x:KeymultiValueConverter//Window.ResourcesTextBox Text{Binding PathPrice, Converter{StaticResource priceConverter}}/TextBox /Window 多重绑定 可以将多个字段绑定到同一个输出控件可以通过 StringFormat 或 MultiBinding.Converter 来格式化数据。多重绑定的值转换器需要实现的接口是 IMultiValueConverter与 IValueConverter 接口比较类似只是转换函数的第一个参数改成了数组形式。 TextBlock Grid.Row4 Grid.Column0TextBlock.TextMultiBinding StringFormat{}{0}, {1}, {2}Binding PathPrice/Binding PathOrderDate/Binding PathVolume//MultiBinding/TextBlock.Text/TextBlockTextBlock Grid.Row5 Grid.Column0TextBlock.TextMultiBinding Converter{StaticResource multiValueConverter}Binding PathPrice/Binding PathVolume//MultiBinding/TextBlock.Text/TextBlock public class MultiValueConverter : IMultiValueConverter {public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture){decimal price (decimal)values[0];int volume (int)values[1];return (price * volume).ToString(C);}public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture){throw new NotSupportedException();} } 完整代码如下 MainWindow.xaml Window x:ClassTestDataConverter.MainWindowxmlnshttp://schemas.microsoft.com/winfx/2006/xaml/presentationxmlns:xhttp://schemas.microsoft.com/winfx/2006/xamlxmlns:dhttp://schemas.microsoft.com/expression/blend/2008xmlns:mchttp://schemas.openxmlformats.org/markup-compatibility/2006xmlns:localclr-namespace:TestDataConvertermc:IgnorabledTitleMainWindow Height450 Width800Window.Resourceslocal:PriceConverter x:KeypriceConverter/local:PriceToBackgroundConverter x:KeypriceToBackgroundConverter MinimumPriceToHighlight100 DefaultBrush{x:Null} HighlightBrushOrange/local:ImagePathConverter x:KeyimagePathConverter/local:MultiValueConverter x:KeymultiValueConverter//Window.ResourcesGrid NamemyGrid Background{Binding PathPrice, Converter{StaticResource priceToBackgroundConverter}}Grid.ColumnDefinitionsColumnDefinition/ColumnDefinition//Grid.ColumnDefinitionsGrid.RowDefinitionsRowDefinition/RowDefinition/RowDefinition/RowDefinition/RowDefinition/RowDefinition//Grid.RowDefinitionsTextBlock Grid.Row0 Grid.Column0 Text{Binding PathPrice, StringFormatConvertDirectly:{0:C}}/TextBlockTextBox Grid.Row0 Grid.Column1 Text{Binding PathPrice, StringFormat{}{0:C}}/TextBoxTextBlock Grid.Row1 Grid.Column0ConvertWithConverter:/TextBlockTextBox Grid.Row1 Grid.Column1 Text{Binding PathPrice, Converter{StaticResource priceConverter}}/TextBoxTextBlock Grid.Row2 Grid.Column0ConvertDateTime:/TextBlockTextBox Grid.Row2 Grid.Column1 Text{Binding PathOrderDate, StringFormat{}{0:s}}/TextBoxTextBlock Grid.Row3 Grid.Column0ConvertImagePath:/TextBlockImage Grid.Row3 Grid.Column1 StretchNone HorizontalAlignmentLeft Source{Binding PathImage, Converter{StaticResource imagePathConverter}}/ImageTextBlock Grid.Row4 Grid.Column0TextBlock.TextMultiBinding StringFormat{}{0}, {1}, {2}Binding PathPrice/Binding PathOrderDate/Binding PathVolume//MultiBinding/TextBlock.Text/TextBlockTextBlock Grid.Row5 Grid.Column0TextBlock.TextMultiBinding Converter{StaticResource multiValueConverter}Binding PathPrice/Binding PathVolume//MultiBinding/TextBlock.Text/TextBlock/Grid /WindowMainWindow.xaml.cs using System; using System.Collections.Generic; using System.ComponentModel; using System.Globalization; using System.IO; using System.Runtime.CompilerServices; using System.Windows; using System.Windows.Controls; using System.Windows.Data; using System.Windows.Media; using System.Windows.Media.Imaging;namespace TestDataConverter;public class ViewModelBase : INotifyPropertyChanged {public event PropertyChangedEventHandler? PropertyChanged;protected virtual void OnPropertyChanged([CallerMemberName] string? propertyName null){PropertyChanged?.Invoke(this, new PropertyChangedEventArgs(propertyName));}protected virtual bool SetPropertyT(ref T member, T value, [CallerMemberName] string? propertyName null){if (EqualityComparerT.Default.Equals(member, value)){return false;}member value;OnPropertyChanged(propertyName);return true;} }public class Order : ViewModelBase {public decimal price 0;public decimal Price { get price; set SetProperty(ref price, value); }public int volume 0;public int Volume { get volume; set SetProperty(ref volume, value); }public DateTime orderDate DateTime.Now;public DateTime OrderDate { get orderDate; set SetProperty(ref orderDate, value); }public string image string.Empty;public string Image { get image; set SetProperty(ref image, value); } } [ValueConversion(typeof(decimal), typeof(string))] public class PriceConverter : IValueConverter {public object Convert(object value, Type targetType, object parameter, CultureInfo culture){decimal price (decimal)value;return price.ToString(C, culture);}public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture){string price (string)value;if (decimal.TryParse(price, System.Globalization.NumberStyles.Any, culture, out decimal result)){return result;}return value;} } [ValueConversion(typeof(decimal), typeof(Brush))] public class PriceToBackgroundConverter : IValueConverter {public decimal MinimumPriceToHighlight { get; set; }public Brush HighlightBrush { get; set; }public Brush DefaultBrush { get; set; }public object Convert(object value, Type targetType, object parameter,System.Globalization.CultureInfo culture){decimal price (decimal)value;if (price MinimumPriceToHighlight)return HighlightBrush;elsereturn DefaultBrush;}public object ConvertBack(object value, Type targetType, object parameter,System.Globalization.CultureInfo culture){throw new NotSupportedException();} } public class ImagePathConverter : IValueConverter {private string imageDirectory Directory.GetCurrentDirectory();public string ImageDirectory{get { return imageDirectory; }set { imageDirectory value; }}public object Convert(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture){string imagePath Path.Combine(ImageDirectory, (string)value);return new BitmapImage(new Uri(imagePath));}public object ConvertBack(object value, Type targetType, object parameter, System.Globalization.CultureInfo culture){throw new NotSupportedException(The method or operation is not implemented.);} } public class MultiValueConverter : IMultiValueConverter {public object Convert(object[] values, Type targetType, object parameter, System.Globalization.CultureInfo culture){decimal price (decimal)values[0];int volume (int)values[1];return (price * volume).ToString(C);}public object[] ConvertBack(object value, Type[] targetTypes, object parameter, System.Globalization.CultureInfo culture){throw new NotSupportedException();} }public partial class MainWindow : Window {public MainWindow(){InitializeComponent();myGrid.DataContext Order;Order.Price 100;Order.Volume 10;Order.OrderDate DateTime.Now;Order.Image image1.gif;}public Order Order new Order();private void Button_Click(object sender, RoutedEventArgs e){Console.WriteLine();} }
http://www.dnsts.com.cn/news/127628.html

相关文章:

  • 深圳营销策划公司大连百度快速排名优化
  • 视频教学网站cms网页浏览器是系统软件吗
  • 个人网站 论坛wordpress安装网站
  • 爱佳倍 北京网站长春免费建网站
  • 网站被别人备案社区网站建设平台
  • 旅游网站开发设计毕设论文莆田网站自助建站
  • 河北省和城乡建设厅网站南京学校网站建设策划
  • 郑州网站推广效果泰安网络安装
  • 外贸网站建设维护wordpress防cc攻击
  • 有可以花钱让人做问券的网站吗wordpress 替换google字体
  • 网站建设优劣势分析淘宝客网站源码和模版有什么区别
  • 宏升温岭网站建设宁夏做网站
  • 站群网站源码新房装修效果图大全2022新款
  • 网站制作费用申请上传网站 php 服务器
  • 做网站不给源码网站建设方案免费
  • 网站建站请示烟台公司网站定制
  • 网站建设 华南商网广安网站建设兼职
  • 教育类网站建站一个公司建n网站
  • 沂水网站制作企业 网站备案 法人
  • 川汇网站建设网页加速器app
  • 网站建设与维护是做什么做数据可视化的网站
  • 织梦小说网站源wap站网站建设过程中的系统结构图
  • 网页排版精美的中文网站ppt
  • 网站管理的主要内容wordpress 优缺点
  • 山东大禹建设集团网站用什么网站做封面最好
  • 正规东莞网站建设友情链接页面
  • 网站及其建设的心得网站建设费用申请报告
  • 影视网站建设方案物价工作信息网站建设
  • 如何查询一个网站的空间服务商公司名称logo设计图免费
  • html个人网页制作源代码常德seo公司