Я пытаюсь создать WPF UserControl
. В моем контроле я хочу привязать Image
Source
к объекту Source
моего объекта. Вот то, что я до сих пор:WPF привязка не работает
XAML файл:
<UserControl x:Class="DeletableObjectPresenter.DeletableObjectPresenter" 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">
<Grid ShowGridLines="True">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
<ColumnDefinition Width="*"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Image Source="{Binding Source}"></Image>
</Grid>
</UserControl>
Код:
public ImageSource Source {
get {
return (ImageSource) GetValue(SourceProperty);
}
set {
SetValue(SourceProperty, value);
}
}
public static readonly DependencyProperty SourceProperty = DependencyProperty.Register(
"Source", typeof(ImageSource), typeof(DeletableObjectPresenter), new PropertyMetadata(new BitmapImage(
new Uri("pack://application:,,,/DeletableObjectPresenter;component/Resources/StandartView.png",
UriKind.Absolute))));
Когда я запускаю проект, я не вижу ожидаемого изображения. Что я делаю не так?