【发布时间】:2015-12-30 17:15:08
【问题描述】:
我有一个 UserControl 文件,该文件有一个文本框,我想将它绑定到代码隐藏文件中的一个属性,但由于某种原因,我无法将其绑定。有人可以告诉我我做错了什么。提前致谢。
XAML:
<ContentDialog Width="200" Height="400" Background="White" Padding="-40,-20" x:Name="addGreetingDialog" PrimaryButtonText="Save" SecondaryButtonText="Cancel" PrimaryButtonClick="addGreetingDialog_PrimaryButtonClick">
<Grid Margin="-25,0,-25,0">
<Grid.RowDefinitions>
<RowDefinition Height="50"></RowDefinition>
<RowDefinition Height="40"></RowDefinition>
<RowDefinition Height="40"></RowDefinition>
</Grid.RowDefinitions>
<Border Grid.Row="0">
<Border.Background>
<LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
<GradientStop Color="#FF686868" Offset="0"/>
<GradientStop Color="#FF515151" Offset="1"/>
<GradientStop Color="#FF676767" Offset="0.5"/>
</LinearGradientBrush>
</Border.Background>
<TextBlock HorizontalAlignment="Center" FontSize="24" Foreground="White" FontFamily="ms-appx:/Assets/Fonts/Roboto-Light.ttf#Roboto"
Margin="10">Add Greetings</TextBlock>
</Border>
<TextBox Grid.Row="2" PlaceholderText="Greeting" Text="{Binding NewGreeting, Mode=TwoWay}"></TextBox>
</Grid>
</ContentDialog>
代码背后:
private string _newGreeting;
public string NewGreeting { get { return _newGreeting; } set { _newGreeting = value; } }
public AddGreeting()
{
this.InitializeComponent();
}
private async void addGreetingDialog_PrimaryButtonClick(global::Windows.UI.Xaml.Controls.ContentDialog sender, global::Windows.UI.Xaml.Controls.ContentDialogButtonClickEventArgs args)
{
}
【问题讨论】:
-
你在设置数据上下文吗?
-
没有。我不知道我必须这样做。你能告诉我你的意思吗? @GabrielDuarte