2012-04-19 4 views
1

これは単にDataContext="{x:Static Brushes.Blue}"作成し、Value="{Binding}"Value="{Binding DataContext}"を変更する私のためXAMLでDataContextをStaticプロパティに設定するにはどうすればよいですか?

<UserControl x:Class="BenchmarkPlus.PMT.UI.Views.Circle" 
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
      mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300" x:Name="root" 
      DataContext="{Binding Source={x:Static Brushes.Blue}}"> 
    <UserControl.Resources> 
     <Style TargetType="Ellipse"> 
      <Setter Property="Fill" Value="{Binding DataContext}" /> 
     </Style> 
    </UserControl.Resources> 
    <Grid> 
     <Ellipse Stroke="Black"></Ellipse> 
    </Grid> 
</UserControl> 

enter image description here

答えて

4

が機能していません。

バインディング式でパスを指定すると、常にDataContextからの相対パスになります。したがって、{Binding DataContext}を使用すると、実際にはDataContext.DataContextにバインドされています。

+0

感謝をしたいと思います。私はそれが何か単純でなければならないことを知っていた。しかし、私はちょうどバインディング部分を変更する必要があった、DataContext値はいずれかの方法で働いた –

1

私はあなたが

<UserControl x:Class="BenchmarkPlus.PMT.UI.Views.Circle" 
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" 
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
      xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
      xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
      mc:Ignorable="d" d:DesignHeight="300" d:DesignWidth="300" x:Name="root" 
      DataContext="{x:Static Brushes.Blue}"> 
    <UserControl.Resources> 
     <Style TargetType="Ellipse"> 
      <Setter Property="Fill" Value="{Binding}" /> 
     </Style> 
    </UserControl.Resources> 
    <Grid> 
     <Ellipse Stroke="Black"></Ellipse> 
    </Grid> 
</UserControl> 
関連する問題