に基づいてPath
内部に設定する方法がわかりません:UserControl
Parameter
ユーザーコントロール:
<UserControl x:Class="WpfApplication3.TestControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:diagnostics="clr-namespace:System.Diagnostics;assembly=WindowsBase">
<Grid>
<TextBox Text="{Binding Path=MyPath}"/>
</Grid>
</UserControl>
背後にあるコード:
public partial class TestControl : UserControl
{
public string MyPath
{
get { return (string)GetValue(MyPathProperty); }
set { SetValue(MyPathProperty, value); }
}
public static readonly DependencyProperty MyPathProperty =
DependencyProperty.Register("MyPath", typeof(string), typeof(TestControl), new UIPropertyMetadata(""));
}
そして、私がそれをどのように使用する予定か:
<local:TestControl MyPath="FirstName"></local:TestControl>
DataContext
親オブジェクトから取得され、内部にプロパティをUser
持つのクラスが含まれます。FirstName
目標は、任意のパスにバインドできるユーザーコントロールを用意することです。とても簡単なはずですが、私はそのテクノロジーに非常に慣れておらず、解決策を見つけることができませんでした。