<UserControl x:Class="DXApplication1.Control.UserControl1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:local="clr-namespace:DXApplication1.Control"
mc:Ignorable="d"
x:Name="uc"
d:DesignHeight="200" d:DesignWidth="200">
<TextBox x:Name="textBox" HorizontalAlignment="Left" Height="23"
Text="{Binding TextT, Mode=TwoWay,ElementName=uc}"
TextWrapping="Wrap" VerticalAlignment="Top" Width="120"/>
</Grid>
</UserControl>
public partial class UserControl1 : UserControl
public UserControl1()
InitializeComponent();
public string TextT
get { return (string )GetValue(TextTProperty); }
set { SetValue(TextTProperty, value); }
// 当外部绑定后,数据变化时,属性会变化,但是界面不会更新
//public static readonly DependencyProperty TextTProperty =
// DependencyProperty.Register("TextT", typeof(string ), typeof(UserControl1), new PropertyMetadata(null));
// 当外部绑定后,数据变化时,界面更新
public static readonly DependencyProperty TextTProperty =
DependencyProperty.Register("TextT", typeof(string), typeof(UserControl1), new PropertyMetadata(null, (s, e) =>
((UserControl1)s).TextT = (string)e.NewValue;
<dx:ThemedWindow
x:Class="DXApplication1.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:dx="http://schemas.devexpress.com/winfx/2008/xaml/core"
xmlns:Views="clr-namespace:DXApplication1.Views"
xmlns:control="clr-namespace:DXApplication1.Control"
xmlns:viewmodels="clr-namespace:DXApplication1.ViewModels"
Title="MainWindow" Height="800" Width="1000">
<dx:ThemedWindow.DataContext>
<viewmodels:MainViewModel x:Name="viewModel"/>
</dx:ThemedWindow.DataContext>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<control:UserControl1 Grid.Row="1" TextT="{Binding ttt, Mode=TwoWay}"></control:UserControl1>
</Grid>
</dx:ThemedWindow>
public class MainViewModel : ViewModelBase
private string _t;
public string ttt
get { return _t; }
_t = value;
RaisePropertiesChanged(nameof(ttt));
<UserControl x:Class="DXApplication1.Control.UserControl1" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2...
Required、StringLength、Range、RegularExpression、Custom
Model层
public class InfoModel : NotifyPropertyBase
//public eve.
主界面是一个TableControl控件,TableItems根据按键动态添加,所添加的TableItems为UserControl,UserControl类似view层,不过可以嵌入window里,UserControl有自己的datacontext,在其下的控件采用{binding path=XX},并没有产生绑定效果
经过调试检查,DataContext设置正确,猜...
// 此类用于实现绘制一条水平分隔线, 按F5运行一次,再拖动当前控件到Form窗体即可看到
// 自定义属性:DrawLineColor和自定义事件ThisLine_Selected
public partial class UserControl1 : UserC
Usercontrol可以将已有的控件重新组合为新的控件,本文将会说明如何实现前台代码设置Usercontol的属性以及事件。
首先,我们先新建一个Usercontrol,命名为:UC
UC中,有一个Label和一个Button。
UC的 LabelText 属性与 Label 的 Content 绑定在一起。
UC的BTNClick属性与Button的Click事件关联在一起。
xam...
官方Github的Wiki文档
乘风破浪,遇见Stylet超清爽WPF御用MVVM框架,爱不释手的.Net Core轻量级MVVM框架
乘风破浪,超清爽WPF御用MVVM框架Stylet,启动到登录设计的高阶实战
【WPF on .NET Co
Wpf开发过程中,最经常使用的功能之一,就是用户控件(UserControl)了。用户控件可以用于开发用户自己的控件进行使用,甚至可以用于打造一套属于自己的UI框架。依赖属性(DependencyProperty)是为用户控件提供可支持双向绑定的必备技巧之一,同样用处也非常广泛。
以下案例,为了图方便,我以之前的博客的基础为模板,直接进行开发。如有遇到疑问的地方,可以查看先前的博客(W...
1)在FrameworkElement类下有两个重要的属性。利用这两个属性,可以实现UI数据直接与后台的类进行绑定2)前端UI界面属性值等动态与后台绑定的方式有多种,此处列出后台设置DataContext以及前端设置DataContext的两种方式,以及数据双向绑定的最佳实践纯前端的方式好处在于,编译一下,就可以在设计阶段看到效果。
1)先定义好我们的类
2)在前端按照步骤引入
后台设置DataContext
在设计阶段是看不到效果的,但是灵活性更高,属性值不用写死
1)定义一个类
2)在当前窗口加载时,进