3

ビュー ウィンドウに MahApps Metro ツールを使用した 1 つの wpf アプリケーションを作成しました。私のアプリケーションは問題なく動作していますが、バインディング エラーが出力ウィンドウに表示されます。そのエラーに記載されているコードは使用していません。

エラーは次のとおりです。

参照 'RelativeSource FindAncestor、AncestorType='MahApps.Metro.Controls.Glow'、AncestorLevel='1'' でバインディングのソースが見つかりません。BindingExpression:Path=GlowColor; DataItem=null; ターゲット要素は 'SolidColorBrush' (HashCode=9047482) です。ターゲット プロパティは 'Color' (タイプ 'Color')

xaml コード:

<Controls:MetroWindow 
    x:Name="MainWin"
    x:Class="TimeSheet.DayView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:l="clr-namespace:TimeSheet.Views.DataTemplateSpace"
    xmlns:sys="clr-namespace:System;assembly=mscorlib"
    xmlns:Controls="clr-namespace:MahApps.Metro.Controls;assembly=MahApps.Metro"
    Title="DayView" Width="596" Height="596">

<Window.Resources>
    <ResourceDictionary>
        <ResourceDictionary.MergedDictionaries>
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Colours.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Fonts.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Controls.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/Blue.xaml" />
            <ResourceDictionary Source="pack://application:,,,/MahApps.Metro;component/Styles/Accents/BaseLight.xaml" />
        </ResourceDictionary.MergedDictionaries>

<DataTemplate x:Key="DefaultDataTemplate">
            <StackPanel Orientation="Horizontal" Width="596">
                <TextBox Text="{Binding ClientNameBinding}" Background="Transparent" Padding="0" Margin="0" BorderThickness="0" TextWrapping="Wrap" Width="145"/>
                <TextBox Text="{Binding ApplicationNameBinding}" Background="Transparent" Padding="0" Margin="0" BorderThickness="0" TextWrapping="Wrap" Width="90"/>
                <TextBox Text="{Binding StartTimeBinding}" Background="Transparent" Padding="0" Margin="0" BorderThickness="0" TextWrapping="Wrap" Width="100"/>
                <TextBox Text="{Binding StopTimeBinding}" Background="Transparent" Padding="0" Margin="0" BorderThickness="0" TextWrapping="Wrap" Width="60"/>
                <TextBox Text="{Binding ProjectNameBinding}" Background="Transparent" Padding="0" Margin="0" BorderThickness="0" TextWrapping="Wrap" Width="130"/>
                <TextBox Text="{Binding TaskNameBinding}" Background="Transparent" Padding="0" Margin="0" BorderThickness="0" TextWrapping="Wrap" Width="71"/>
            </StackPanel>
        </DataTemplate>

<StackPanel Orientation="Horizontal" Margin="-1,93,1,434" RenderTransformOrigin="1.155,0.47" Height="25">
            <TextBox Text="Client" HorizontalContentAlignment="Center" Width="145" Foreground="White" Background="Blue" Padding="0" BorderThickness="0" VerticalContentAlignment="Center"/>
            <TextBox Text="Application" HorizontalContentAlignment="Center" Width="90" Foreground="White" Background="Blue" Padding="0" BorderThickness="0" VerticalContentAlignment="Center"/>
            <TextBox Text="StartTime" HorizontalContentAlignment="Center" Canvas.Left="148" Canvas.Top="86" Width="100" Foreground="White" Background="Blue" Padding="0" BorderThickness="0" RenderTransformOrigin="0.5,0.5" VerticalContentAlignment="Center"/>
            <TextBox Text="StopTime" HorizontalContentAlignment="Center" Width="60" RenderTransformOrigin="0.471,0.692" Foreground="White" Background="Blue" Padding="0" BorderThickness="0" VerticalContentAlignment="Center"/>
            <TextBox Text="Task" HorizontalContentAlignment="Center" Canvas.Left="378" Canvas.Top="86" Width="130" Foreground="White" Background="Blue" Padding="0" BorderThickness="0" VerticalContentAlignment="Center"/>
            <TextBox Text="Project" HorizontalContentAlignment="Center" Width="71" Foreground="White" Background="Blue" Padding="0" BorderThickness="0" VerticalContentAlignment="Center"/>
        </StackPanel>

<ListBox x:Name="listBox1" ItemsSource="{Binding}" Margin="0,131,0,59" ItemTemplateSelector="{StaticResource templateSelector}" SelectionMode="Single">
            <ListBox.ItemContainerStyle>
                <Style TargetType="{x:Type ListBoxItem}">
                    <EventSetter Event="MouseDoubleClick" Handler="listBox1_MouseDoubleClick">
                    </EventSetter>
                </Style>
            </ListBox.ItemContainerStyle>
        </ListBox>

</Controls:MetroWindow>
4

1 に答える 1

8

グローバル スタイル、テンプレート、またはユーザー コントロールに関連するバインディング エラーのようです。

バインディング エラーのデバッグについては、こちらに書きました。

要約すると、セミコロンとコンマで改行を追加し、エラーを逆に読むと最も簡単です

エラーでそれを行うと、次のようになります。

ターゲット プロパティは 'Color' (タイプ 'Color')
ターゲット要素は 'SolidColorBrush' (HashCode=9047482) です。
DataItem=null;
参照 'RelativeSource FindAncestor、バインディングのソースが見つかりません。
    AncestorType='MahApps.Metro.Controls.Glow',
    AncestorLevel='1''。
    BindingExpression:Path=GlowColor;

それはあなたにそれを伝えます:

  • どこかにColorバインディング エラーの原因となるプロパティがあります。

  • そのプロパティはSolidColorBrushオブジェクトにあります

  • そのDataContext商品のはnullです。

  • 評価に問題があるバインディングは、オブジェクトのプロパティを見つけて使用できるように、ビジュアル ツリーのさらに上のオブジェクトをRelativeSource探しているバインディングです。MahApps.Metro.Controls.GlowGlowColor

アプリケーションで を検索して、GlowColorそれが見つかるかどうかを確認してください。おそらくオブジェクトColours.xamlが含まれているため、ファイルにある可能性が最も高いです。SolidColorBrush

于 2013-06-28T14:46:06.590 に答える