Image 컨트롤에서 상속 된 사용자 지정 클래스를 빌드하려고하는데 바인딩하는 데 문제가 있습니다. 내가응용 프로그램 리소스에서 DependancyProperty를 컨트롤 DependancyProperty (리소스를 사용하는)에 바인딩
그래서 내 App.xaml 자원에 내가 몇 DrawingImages이 하나의 예 (즉, 벡터 이미지를 위해 제공되는 기능) 내 자원 DrawingImage을 사용하고
:
<DrawingImage x:Key="Shutdown">
<DrawingImage.Drawing>
<DrawingGroup>
<DrawingGroup.Children>
<DrawingGroup>
<DrawingGroup.Children>
<GeometryDrawing Brush="{x:Null}">
<GeometryDrawing.Pen>
Here--> <Pen Brush="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:IconImage}}, Path=Colour, UpdateSourceTrigger=PropertyChanged}" Thickness="2" />
</GeometryDrawing.Pen>
<GeometryDrawing.Geometry>
<PathGeometry FillRule="Nonzero" Figures="M8.332,4.941C5.759,6.271 4,8.956 4,12.052 4,16.47 7.582,20.052 12,20.052 16.418,20.052 20,16.47 20,12.052 20,8.911 18.19,6.193 15.555,4.884" />
</GeometryDrawing.Geometry>
</GeometryDrawing>
Here--> <GeometryDrawing Brush="{Binding RelativeSource={RelativeSource Mode=FindAncestor, AncestorType={x:Type local:IconImage}}, Path=Colour, UpdateSourceTrigger=PropertyChanged}" Pen="{x:Null}">
<GeometryDrawing.Geometry>
<RectangleGeometry RadiusX="0" RadiusY="0" Rect="11,2,2,10" />
</GeometryDrawing.Geometry>
</GeometryDrawing>
</DrawingGroup.Children>
<DrawingGroup.ClipGeometry>
<RectangleGeometry Rect="0,0,24,24" />
</DrawingGroup.ClipGeometry>
</DrawingGroup>
</DrawingGroup.Children>
</DrawingGroup>
</DrawingImage.Drawing>
</DrawingImage>
및
public class IconImage : Image
{
public enum Icons
{
None,
Shutdown,
Minimize
}
private Icons _icon;
public Icons Icon
{
get { return _icon; }
set
{
_icon = value;
if (value == Icons.None)
{
Visibility = Visibility.Hidden;
}
else
{
Visibility = Visibility.Visible;
this.SetResourceReference(Image.SourceProperty, value.ToString());
}
}
}
public static readonly DependencyProperty ColourProperty = DependencyProperty.Register("Colour", typeof(Brush), typeof(IconImage), new PropertyMetadata(Brushes.Black));
public Brush Colour
{
get { return (Brush)GetValue(ColourProperty); }
set { SetValue(ColourProperty, value); }
}
}
Usasge : 다음과 같이 내 사용자 정의 클래스를 구축
<local:IconImage Icon="Shutdown" Colour="CornflowerBlue" />
DrawingImages의 내 브러시 바인딩이 맞춤 클래스의 내 색상 DependancyProperty에 바인딩되지 않고이를 수행하는 방법이나 가능한 경우 생각이 없습니다. 브러쉬를 하드 코딩하면 완벽하게 작동합니다 (당연히). 그저 디자인 타임에 컨트롤의 색상을 변경하거나 코드 뒤에서 언제든지 색상을 변경할 수 있어야합니다.
미리 감사드립니다.
-Sean-는
'DrawingImage'는 어디에서 사용 되었습니까? 'DrawingImage'에 대해'local : IconImage'의'AncestorType'을 가지고 계시나요? – Iron
Icon 속성을 설정할 때 사용됩니다. this.SetResourceReference (Image.SourceProperty, value.ToString()); 이 경우 DynamicReference를 "Shutdown"으로 설정합니다. –
'x : Key = "Shutdown"'리소스를 사용하는 코드를 보여 주시겠습니까? – Iron