Silverlight 5는 스타일에서 데이터 바인딩을 도입했습니다. 콘텐츠 템플릿에있는 이미지 원본을 단추 스타일로 바인딩하고 싶습니다. 이미지 소스 속성을 스타일로 설정하려고하는 아래 코드를 사용하고 있습니다.Silverlight 5에서 스타일로 바인딩하기
ImageSource 내가 생성 한 종속성 속성입니다 // 스타일
<UserControl x:Class="MGPIControls_Simple.ButtonControl"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:vsm="clr-namespace:System.Windows;assembly=System.Windows"
Height="40" Width="40"
mc:Ignorable="d" x:Name="ButtonControlSample">
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.Resources>
<Style x:Key="ImageButtonStyle" TargetType="Button">
<Setter Property="BorderBrush" Value="Transparent"/>
<Setter Property="BorderThickness" Value="0"/>
<Setter Property="Background" Value="Transparent"/>
<Setter Property="ContentTemplate">
<Setter.Value>
<DataTemplate>
<!-- binding in style -->
<Image Source="{Binding ImageSource}"
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
Stretch="Fill"/>
</DataTemplate>
</Setter.Value>
</Setter>
</Style>
</Grid.Resources>
<Button x:Name="ButtonBase" Style="{StaticResource ImageButtonStyle}"
HorizontalAlignment="Stretch" VerticalAlignment="Stretch"/>
</Grid>
. 이미지 원본 속성을 바인딩하지 않고 일부 이미지 URL에 정적으로 유지하면 문제가 없지만 바인딩이 작동하지 않습니다. 위의 방법으로 내가 잘못 생각한 부분을 알려주십시오.
이 속성은 어디에 정의되어 있습니까? 그것은 DataContext에 존재합니까? – Martin