如何重用用户控件?
我有:
<UserControl ...
DataContext="{Binding IPAddressControlVM, Source={StaticResource Locator}}">
<Grid >
<TextBox Text="{Binding Path=First}" />
<TextBox Text="{Binding Path=Second}" />
</Grid>
</UserControl>
视图模型:
private string first;
private string second;
public string First
{
get
{
return first;
}
set
{
Set<string>(() => this.First, ref first, value);
RaisePropertyChanged("First");
}
}
public string Second
{
get
{
return second;
}
set
{
Set(() => this.Second, ref second, value);
RaisePropertyChanged("Second");
}
}
免得我拥有
<Window x:Class="MainWindow"
DataContext="{Binding MainWindowVM, Source={StaticResource Locator}}"
...>
<Grid>
<local:MyUserControl/>
</Grid>
如何将uesr控件的属性绑定到MainWindow-ViewModel?
我的意思是,我需要类似的东西:
<local:MyUserControl First={Binding FirstTxt} First={Binding SecondTxt}/>