I am trying to pass data to a shader I wrote in HLSL for my WPF image processing I need to make. From what I've tested the shader works but the binding does not.
<Grid HorizontalAlignment="Center" VerticalAlignment="Center">
<Image x:Name="SourceImage" HorizontalAlignment="Left"
Source="{Binding InputImageSource, FallbackValue={StaticResource DefaultImage}, TargetNullValue={StaticResource DefaultImage}, Mode=TwoWay,
RelativeSource={RelativeSource FindAncestor,
AncestorType={x:Type imagePreview:ImagePreview}}}"/>
<Rectangle HorizontalAlignment="Left" Width="{Binding Value, ElementName=Slider}"
Margin="{Binding Margin, ElementName=SourceImage}">
<Rectangle.Effect>
<shader:ImageProcessor Brightness="{Binding BrightnessSlider, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type imagePreview:SettingsBar}}}"
Gamma="{Binding GammaSlider, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type imagePreview:SettingsBar}}}"
MultiplyColor="{Binding MultiplyColor.Value, Converter={StaticResource HexToColor}, Mode=OneWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type imagePreview:SettingsBar}}}"></shader:ImageProcessor>
</Rectangle.Effect>
<Rectangle.Fill>
<ImageBrush ImageSource="{Binding OutImageSource, FallbackValue={StaticResource DefaultImage}, TargetNullValue={StaticResource DefaultImage},
RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type imagePreview:ImagePreview}}}"
Stretch="UniformToFill" AlignmentX="Left" AlignmentY="Top">
</ImageBrush>
</Rectangle.Fill>
</Rectangle>
<Slider x:Name="Slider" Maximum="{Binding ActualWidth, ElementName=SourceImage}"
Value="{Binding ActualWidth, ConverterParameter=0.5, Converter={converters:PercentageOfImage},
ElementName=SourceImage, Mode=OneWay}"
VerticalAlignment="Bottom" Margin="{Binding Margin, ElementName=SourceImage}"/>
</Grid>
And here is the usercontrol for the settings
** <Border BorderBrush="{StaticResource 4DGrey1}" BorderThickness="5, 0, 0, 0" Margin="0, 0, 0, 10">
<StackPanel>
<Expander Header="IMPORT / EXPORT" Style="{StaticResource MontserratSemiBold}" Width="200" IsExpanded="True" x:Name="ImportExport">
<StackPanel Style="{StaticResource MontserratRegular}">
<TextBlock Text="- Select input / output folder" Margin="15,5,0,0" Style="{StaticResource MontserratExtraLight}"/>
<StackPanel Orientation="Horizontal" Margin="10,5,10,0">
<Button Margin="5,0,0,0" Click="Button_Import">
<Image Source="../Resources/Images/Icons/folder-15.png" Width="70" Height="Auto" x:Name="ButtonImport"/>
</Button>
<Button Margin="20, 0, 0, 0" Style="{StaticResource MontserratLight}" Click="Button_Export">
<Image Source="../Resources/Images/Icons/folder-16.png" Width="70" Height="Auto"/>
</Button>
</StackPanel>
</StackPanel>
</Expander>
<Expander Header="ADJUSTMENT" Style="{StaticResource MontserratMedium}" Width="{Binding Width, ElementName=ImportExport}" IsExpanded="True">
<StackPanel>
<TextBlock Text="- Brightness" Margin="15,5,0,0" Style="{StaticResource MontserratExtraLight}"/>
<Slider Margin="25,0,5,0" Minimum=".5" Maximum="5"
Value="{Binding BrightnessSlider, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:SettingsBar}}}"/>
<TextBlock Text="- Gamma" Margin="15,5,0,0" Style="{StaticResource MontserratExtraLight}"/>
<Slider Margin="25,0,5,0" Minimum="0" Maximum="2"
Value="{Binding GammaSlider, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:SettingsBar}}}"/>
<TextBlock Text="- Greyscale type | Equalize" Margin="15,5,0,0" Style="{StaticResource MontserratExtraLight}"/>
<StackPanel Orientation="Horizontal">
<ComboBox x:Name="GrayConversionSelector" ItemsSource="{StaticResource GreyscaleFormats}" Margin="15,5,0,0" Style="{StaticResource MontserratExtraLight}" DropDownClosed="Greytype_Update"
SelectedIndex="2"/>
<CheckBox HorizontalAlignment="Center" Margin="7,5,10,0" VerticalAlignment="Center" IsChecked="{Binding EqualizeToggle, Mode=TwoWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:SettingsBar}}}"/>
</StackPanel>
<TextBlock Text="- Color section tool" Margin="15,5,0,0" Style="{StaticResource MontserratExtraLight}"/>
<xctk:DropDownButton Margin="15, 5, 10, 0" Style="{StaticResource MontserratLight}" Background="{StaticResource 4DWhite}">
<xctk:DropDownButton.DropDownContent>
<xctk:ColorCanvas x:Name="ColorCanvas" SelectedColorChanged="Color_Changed"
SelectedColor="{Binding MultiplyColor, Mode=TwoWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:SettingsBar}}}"/>
</xctk:DropDownButton.DropDownContent>
<Border BorderThickness="1" BorderBrush="{StaticResource 4DGrey2}">
<Rectangle Height="19" Width="132">
<Rectangle.Fill>
<SolidColorBrush Color="{Binding SelectedColor, ElementName=ColorCanvas, FallbackValue={StaticResource 4DWhite}}"/>
</Rectangle.Fill>
</Rectangle>
</Border>
</xctk:DropDownButton>
<Button Content="Reset settings" Margin="15, 10, 10, 0" Style="{StaticResource MontserratLight}" Height="25" Click="Button_Reset"/>
<Slider Margin="25,5,5,0" Minimum="0" Maximum="255"
Value="{Binding BlackControl, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:SettingsBar}}}"/>
<Slider Margin="25,5,5,0" Minimum="0" Maximum="255"
Value="{Binding WhiteControl, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:SettingsBar}}}"/>
</StackPanel>
</Expander>
</StackPanel>
</Border>**
This is what I am using for the binding, and was added to the shader parameters via the properties window. However the error I am getting is as follows:
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='FabricDigitizationTool.UserControls.SettingsBar', AncestorLevel='1''. BindingExpression:Path=MultiplyColor; DataItem=null; target element is 'ColorCanvas' (Name='ColorCanvas'); target property is 'SelectedColor' (type 'Nullable`1')
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='FabricDigitizationTool.UserControls.SettingsBar', AncestorLevel='1''. BindingExpression:Path=BrightnessSlider; DataItem=null; target element is 'ImageProcessor' (HashCode=22367029); target property is 'Brightness' (type 'Double')
System.Windows.Data Error: 4 : Cannot find source for binding with reference 'RelativeSource FindAncestor, AncestorType='FabricDigitizationTool.UserControls.SettingsBar', AncestorLevel='1''. BindingExpression:Path=MultiplyColor.Value; DataItem=null; target element is 'ImageProcessor' (HashCode=22367029); target property is 'MultiplyColor' (type 'Color')
I am getting multiple of these, one for the color and a few doubles, which I assume are having the same issue. The ColorCanvas element is defined as
<xctk:ColorCanvas x:Name="ColorCanvas" SelectedColorChanged="Color_Changed"
SelectedColor="{Binding MultiplyColor, Mode=TwoWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:SettingsBar}}}"/>
This all worked before I was doing it with a shader, but now everything is broken. Whenever a setting in my settingsbar is updated it fires an event that updates the data (Using dependencyProperties) and this event triggers the output image to be reprocessed. I changed this to a shader with some parameters, but this does not want to work.
The values for the shader parameters are 1, 1, and 0xFFFFFF respectively.
If anyone has an idea or requires more information,any help would be greatly appreciated.