在WPF中绑定类的属性至Label控件实现自动更新显示
转载自
https://blog.csdn.net/vanwood/article/details/8077467
class:
public static readonly DependencyProperty _count =
DependencyProperty.Register("count", typeof(int), typeof(DeviceOnlineStatusControl));
public int count
{
get { return (int)GetValue(_count); }
set { SetValue(_count, value); }
}
xaml:
<UserControl x:Class="xx"
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:Client.ViewModule.Controls"
mc:Ignorable="d"
x:Name="Root"
d:DesignHeight="450" d:DesignWidth="800">
<Grid>
<Grid Height="36" Margin="10,0" VerticalAlignment="Top">
<Label Content="总共:" HorizontalAlignment="Left" Margin="222,11,0,0" VerticalAlignment="Top" Width="39"/>
<Label x:Name="Count" Content="{Binding ElementName=Root,Path=count}" HorizontalAlignment="Left" Margin="266,11,0,0" Width="52"/>
</Grid>
</Grid>
</UserControl>

浙公网安备 33010602011771号