Answer the question
In order to leave comments, you need to log in
WPF, how to bind in your controls?
There is a control:
public partial class BackgroundImage : Image
{
public static DependencyProperty SettingsProperty = DependencyProperty.Register("Settings", typeof(BackgroundSettings), typeof(BackgroundImage));
public BackgroundImage()
{
InitializeComponent();
}
public BackgroundSettings Settings
{
get => (BackgroundSettings)GetValue(SettingsProperty);
set => SetValue(SettingsProperty, value);
}
}
public class BackgroundSettings : ViewModelBase
{
/// <summary>
/// Image path.
/// </summary>
public string ImagePath { get; set; }
/// <summary>
/// Image blur.
/// </summary>
public int Blur { get; set; }
}
<Image
x:Class="Malinka.Controls.BackgroundImage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Source="{Binding RelativeSource={RelativeSource Mode=Self}, Path=Settings.ImagePath, Converter={StaticResource BackgroundImageConverter}}"
Stretch="UniformToFill">
<Image.Effect>
<BlurEffect Radius="{Binding RelativeSource={RelativeSource Mode=Self}, Path=Settigns.Blur}"/>
</Image.Effect>
</Image>
System.Windows.Data Error: 40 : BindingExpression path error: 'Settigns' property not found on 'object' ''BlurEffect' (HashCode=43556055)'. BindingExpression:Path=Settings.Blur; DataItem='BlurEffect' (HashCode=43556055); target element is 'BlurEffect' (HashCode=43556055); target property is 'Radius' (type 'Double')
Answer the question
In order to leave comments, you need to log in
Decision:
<Image
x:Class="Malinka.Controls.BackgroundImage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
x:Name="imageBase"
mc:Ignorable="d"
Source="{Binding Settings.ImagePath, ElementName=imageBase, Converter={StaticResource BackgroundImageConverter}}"
Stretch="UniformToFill">
<Image.Effect>
<BlurEffect Radius="{Binding Settings.Blur, ElementName=imageBase}"/>
</Image.Effect>
</Image>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question