<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit" xmlns:System_windows_Controls_Primitives="clr-namespace:System.windows.Controls.Primitives;assembly=System.windows.Controls.Toolkit" x:Class="SilverlightApplication5.MainPage" WIDth="640" Height="480"> <StackPanel x:name="LayoutRoot" Background="White"> <TextBox x:name="tbWIDth" textwrapPing="Wrap" Text="{Binding Mode=TwoWay,ValIDatesOnExceptions=True,Path=RoomWIDth}"/> </StackPanel></UserControl>
RoomWIDth – 属性.
using System;using System.Collections.Generic;using System.linq;using System.Net;using System.windows;using System.windows.Controls;using System.windows.documents;using System.windows.input;using System.windows.Media;using System.windows.Media.Animation;using System.windows.Shapes;namespace SilverlightApplication5{ public partial class MainPage : UserControl { public MainPage() { InitializeComponent(); } private int roomWIDth = 10; public int RoomWIDth { get { return roomWIDth; } set { if (value < 0 || value > 100) { throw new Exception("Data not correct"); } roomWIDth = value; } } }}
我需要添加到Binding源这个类.这是怎么回事?
解决方法 使用Elementname例如:<UserControl xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:toolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit" xmlns:System_windows_Controls_Primitives="clr-namespace:System.windows.Controls.Primitives;assembly=System.windows.Controls.Toolkit" x:Class="SilverlightApplication5.MainPage" WIDth="640" Height="480" name="control"> <!-- ... --> <TextBox Text="{Binding Elementname=control,Mode=TwoWay,Path=RoomWIDth}" x:name="tbWIDth" textwrapPing="Wrap"/>
如果您遇到类似基本绑定的问题,那么您应该阅读它. (WPF/Silverlight)
总结以上是内存溢出为你收集整理的wpf – 如何绑定文本框和属性?全部内容,希望文章能够帮你解决wpf – 如何绑定文本框和属性?所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)