我创建了一个警告窗口来验证用户的删除操作,使用 Window.ShowDialog 并设置 DialogResult。一切正常,除了警告文本没有出现在中TextBlock
,我不知道为什么。这是我的Window
:
<Window x:Class="RoVCo.Windows.VerifyWindow"
....
WindowStyle="None" Padding="10" ResizeMode="NoResize">
<StackPanel>
<TextBlock Height="Auto" Text="{Binding TBText, Mode=OneWay}" Foreground="Yellow" TextWrapping="Wrap" />
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right" Margin="0,10,0,0">
<Button Content="Cancel" Margin="10,0" Width="50" Click="CancelVerify" />
<Button Content="OK" Width="50" Click="ConfirmVerify" />
</StackPanel>
</StackPanel>
</Window>
和班级:
public partial class VerifyWindow : Window
{
public VerifyWindow(string content)
{
InitializeComponent();
_text = content;
}
private string _text = "";
public string TBText { get { return _text; } }
private void CancelVerify(object sender, RoutedEventArgs e)
{
this.DialogResult = false;
this.Close();
}
private void ConfirmVerify(object sender, RoutedEventArgs e)
{
this.DialogResult = true;
this.Close();
}
}
我这样称呼它:
var window = new RoVCo.Windows.VerifyWindow("Removing this skill will erase all DP spent on it from all levels. Continue?");
if (window.ShowDialog() == false) return;