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

织梦网做企业网站需要授权吗做seo前景怎么样

织梦网做企业网站需要授权吗,做seo前景怎么样,石岩附近做网站公司,商城类网站如何做在WPF Samples中有一个关于数据绑定到方法的Demo&#xff0c;该Demo结构如下&#xff1a; 运行效果如下所示&#xff1a; 来看看是如何实现的。 先来看下MainWindow.xaml中的内容&#xff1a; <Window.Resources><ObjectDataProvider ObjectType"{x:Type local…

在WPF Samples中有一个关于数据绑定到方法的Demo,该Demo结构如下:

image-20240621101313200

运行效果如下所示:

来看看是如何实现的。

先来看下MainWindow.xaml中的内容:

<Window.Resources><ObjectDataProvider ObjectType="{x:Type local:TemperatureScale}"MethodName="ConvertTemp" x:Key="ConvertTemp"><ObjectDataProvider.MethodParameters><system:Double>0</system:Double><local:TempType>Celsius</local:TempType></ObjectDataProvider.MethodParameters></ObjectDataProvider><local:DoubleToString x:Key="DoubleToString" /></Window.Resources>

在窗体资源中定义了一个ObjectDataProvider对象与DoubleToString对象。

ObjectDataProvider介绍

image-20240621102324090

ObjectDataProvider类用于包装和创建可以用作绑定源的对象。

 <ObjectDataProvider MethodName="ConvertTemp" >

image-20240621102953193

ObjectDataProvider.MethodName 属性获取或设置要调用的方法的名称。

<ObjectDataProvider.MethodParameters><system:Double>0</system:Double><local:TempType>Celsius</local:TempType>
</ObjectDataProvider.MethodParameters>

image-20240621103147579

ObjectDataProvider.MethodParameters属性获取要传递给方法的参数列表。

绑定到方法

<TextBox Grid.Row="1" Grid.Column="1" Name="tb"><TextBox.Text><Binding Source="{StaticResource ConvertTemp}" Path="MethodParameters[0]"BindsDirectlyToSource="true" UpdateSourceTrigger="PropertyChanged"Converter="{StaticResource DoubleToString}"><Binding.ValidationRules><local:InvalidCharacterRule/></Binding.ValidationRules></Binding></TextBox.Text>
</TextBox>

绑定路径为方法的第一个参数。

使用的转换器是在资源中定义的DoubleToString

BindsDirectlyToSource属性设置为true,表示直接绑定到数据源对象,而不是是绑定到数据源对象的某个属性。

<Binding.ValidationRules><local:InvalidCharacterRule/>
</Binding.ValidationRules>

image-20240621104346213

Binding.ValidationRules属性用于定义数据绑定的验证规则。这些规则用于在数据绑定过程中验证输入数据的有效性。如果数据不符合验证规则,WPF 可以显示错误信息或采取其他措施来处理无效数据。

这里使用的是InvalidCharacterRule对象。

<ComboBox Grid.Row="1" Grid.Column="2" 
SelectedValue="{Binding Source={StaticResource ConvertTemp},
Path=MethodParameters[1], BindsDirectlyToSource=true}"><local:TempType>Celsius</local:TempType><local:TempType>Fahrenheit</local:TempType>
</ComboBox>

ComboBox绑定到方法的第二个参数。

<Label Content="{Binding Source={StaticResource ConvertTemp}}"
Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="2"/>

绑定到方法的返回值。

现在查看这个方法:

  public string ConvertTemp(double degree, TempType temptype){Type = temptype;switch (temptype){case TempType.Celsius:return (degree*9/5 + 32).ToString(CultureInfo.InvariantCulture) + " " + "Fahrenheit";case TempType.Fahrenheit:return ((degree - 32)/9*5).ToString(CultureInfo.InvariantCulture) + " " + "Celsius";}return "Unknown Type";}

绑定过程梳理

该Demo启动后的界面如下所示:

image-20240621105239909

 <ObjectDataProvider ObjectType="{x:Type local:TemperatureScale}"MethodName="ConvertTemp" x:Key="ConvertTemp"><ObjectDataProvider.MethodParameters><system:Double>0</system:Double><local:TempType>Celsius</local:TempType></ObjectDataProvider.MethodParameters></ObjectDataProvider>

ObjectDataProvider.MethodParameters中设置了方法的参数为0和Celsius。

而0是Double类型,TextBox需要string类型,因此设置了DoubleToString转换器。

该转换器代码如下所示:

 public class DoubleToString : IValueConverter{public object Convert(object value, Type targetType, object parameter,CultureInfo culture) => value?.ToString();public object ConvertBack(object value, Type targetType, object parameter,CultureInfo culture){var strValue = value as string;if (strValue != null){double result;var converted = double.TryParse(strValue, out result);if (converted){return result;}}return null;}}
<ComboBox Grid.Row="1" Grid.Column="2" 
SelectedValue="{Binding Source={StaticResource ConvertTemp},
Path=MethodParameters[1], BindsDirectlyToSource=true}"><local:TempType>Celsius</local:TempType><local:TempType>Fahrenheit</local:TempType>
</ComboBox>

ComboBox的SelectedValue绑定到方法的第二个参数,刚开始也就是Celsius。

<Label Content="{Binding Source={StaticResource ConvertTemp}}"
Grid.Row="2" Grid.Column="1" Grid.ColumnSpan="2"/>

绑定到方法的返回值。

在TextBox中输入了做了数据绑定的验证规则。

InvalidCharacterRule类代码如下所示:

internal class InvalidCharacterRule : ValidationRule
{public override ValidationResult Validate(object value, CultureInfo cultureInfo){var myvalue = 0.00;try{if (((string) value).Length > 0)myvalue = double.Parse((string) value);}catch (Exception e){return new ValidationResult(false, "Illegal characters or " + e.Message);}return new ValidationResult(true, null);}
}

当输入不符合规则时,会有提示,如下图所示:

image-20240621110313599

代码来源

[WPF-Samples/Data Binding/BindingToMethod at main · microsoft/WPF-Samples (github.com)](https://github.com/microsoft/WPF-Samples/tree/main/Data Binding/BindingToMethod)

http://www.hkea.cn/news/687574/

相关文章:

  • 鞍山找工作哪个网站最靠谱千度搜索引擎
  • 济南做网站互联网公司英文seo推广
  • 给企业做网站的公司品牌整合营销传播
  • 互联网技术应用学什么杭州优化建筑设计
  • 重庆网站建设要点襄阳seo优化排名
  • 哪个网站用织梦做的seo站长工具查询系统
  • 本地wordpress 上传搜索引擎优化简历
  • 个人创业做网站软文营销怎么写
  • wordpress相册点击弹出框金华seo全网营销
  • 郑州手机网站建设搜狗网站收录提交入口
  • 清风网站建设抖音推广方式有哪些
  • 工作室网站开发广东网站seo营销
  • 广州正佳广场攻略深圳债务优化公司
  • 如何自己免费建网站seo网站有哪些
  • 南昌网站建设案例如何制作自己的链接
  • wordpress大流量专业的网站优化公司
  • 做进口零食批发网站百度站长管理平台
  • 网站栏目建设存在的问题关键词简谱
  • 网站备案怎么那么麻烦google chrome 网络浏览器
  • 小米手机做网站服务器nba东西部最新排名
  • 做写字楼用哪个网站更好郑州seo代理外包
  • 做网站 淘宝营销策划思路
  • 网页设计要用到什么软件聊城seo优化
  • 用wordpress做网站百度推广管理
  • 一个空间可以放两个网站吗html模板网站
  • 做试用网站的原理网站推广优化平台
  • 软件工程培训机构学费亚马逊seo什么意思
  • 做恶搞网站软件有哪些苏州seo怎么做
  • 怎么做微信小说网站企业网络营销策划方案
  • 网站后台上传图片失败百度下载免费安装最新版