WPF XAML解析使用默认样式时的派生样式时



你好,我的问题是关于wpf xaml解析异常的来源,以及捕获它的方法。到目前为止,尽管从设置中添加了所有例外,但我无法抓住它。<<<<<<<<<<<<<<<<

当我尝试从默认的一种样式中得出一种样式时,它会崩溃。

 Exception thrown: 'System.Windows.Markup.XamlParseException' in PresentationFramework.dll 
    Additional information: 'Provide value on 'System.Windows.StaticResourceExtension' threw an exception.' Line number '13' and line position '22'.
   If there is a handler for thisenter code here exception, the program may be safely continued.

应用样式的地方:

 <Grid Margin="0,0,1,51">
            <StackPanel Name="tbPanel" Margin="80,8,98,90" >
                <TextBox  Name="txtInput0" ></TextBox>
                <TextBox Name="txtOutput0" Style="{StaticResource Custom}" ></TextBox>
            </StackPanel>
        </Grid>

资源部分:

<Window.Resources>
        <Style TargetType="TextBox">
            <Setter Property="Background" Value="DarkMagenta"></Setter>
        </Style>
        <Style TargetType="TextBox" x:Key="Custom" BasedOn="{StaticResource {x:Type TextBox}}">
            <Setter Property="Background" Value="Beige"></Setter>
        </Style>
</Window.Resources>

我试图抓住异常。我从异常设置中添加了所有异常,并在主窗口中添加了try-catch块,但仍然没有。

  public MainWindow()
        {
            try
            {
                InitializeComponent();
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.InnerException.Message);
            }
        }

ps:在XAML设计师中,两个文本框有不同的颜色。

问题是由于以下事实:使用窗口中使用的样式的UI元素。资源部分在资源部分之前声明。

在UI元素解决问题之前移动资源部分。

最新更新