c# - 为什么要使用绑定和依赖属性?
问题描述
我有一个包含按钮的用户控件设计。我在其他地方使用它,并且必须在那里填写一些内容。现在我的问题是,当我更新这个用户控件时,我可以访问它的内容并且我可以填写它。问题是,我应该为此使用绑定吗?为什么?
<Grid Margin="2,5,2,5">
<Border CornerRadius="5" BorderThickness="1" BorderBrush="Black">
<Button x:Name="button" Margin="2, 4, 2, 4"
Content="{Binding content}"
Click="button_Click"
Background="Transparent"
Foreground="Black"
Height="23"
FontSize="10"
Cursor="Hand" Padding="1"
BorderThickness="0" MouseEnter="button_MouseEnter" MouseLeave="button_MouseLeave"></Button>
</Border>
</Grid>
public string content
{
get { return (string)GetValue(contentProperty); }
set { SetValue(contentProperty, value); }
}
public static readonly DependencyProperty contentProperty =
DependencyProperty.Register("content", typeof(string), typeof(ButtonView), new PropertyMetadata(""));
解决方案
推荐阅读
- postgresql - 如何在 PostgreSQL 上的数据库上输入密码?
- caching - 如何使用当前月份作为密钥创建 Gitlab CI 管道缓存
- abap - 将 FOR 与 REDUCE 一起使用时 ABAP 停止舍入
- vuejs3 - 如何使响应的值传递给 app.provide 方法
- java - Android AlertDialog 将按钮对齐到底部不起作用
- azure-application-insights - Log Analytics 查询忽略 ysplit
- swift - 为什么 Swift 运算符重载需要是类型方法?
- python - 应该在 Python 包的模块中还是在导入 Python 包的模块的模块中记录异常?
- docker - 如何从另一个 docker 网络访问 docker 网络(单向访问)
- azure - Get-AzureADGroup 和 Get-AzureADMSGroup 命令的结果缺少 CommonName 属性