我正在尝试将数据传递给我在HLSL中编写的着色器,用于我需要进行的WPF图像处理。根据我的测试,着色器有效,但绑定无效。
<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>
这是设置的用户控件
** <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>**
这是我用于绑定的内容,并通过属性窗口添加到了着色器参数中。但是我得到的错误如下:
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')
我得到了其中的多个,其中一个用于颜色,另一些用于双打,我认为它们存在相同的问题。 ColorCanvas元素定义为
<xctk:ColorCanvas x:Name="ColorCanvas" SelectedColorChanged="Color_Changed"
SelectedColor="{Binding MultiplyColor, Mode=TwoWay, RelativeSource={RelativeSource FindAncestor, AncestorType={x:Type local:SettingsBar}}}"/>
这一切在我使用着色器完成之前都有效,但是现在一切都坏了。每当我的设置栏中的设置被更新时,它都会触发一个更新数据的事件(使用dependencyProperties),并且该事件触发输出图像进行重新处理。我将其更改为具有某些参数的着色器,但这并不起作用。
着色器参数的值分别为1、1和0xFFFFFF。
如果有人有想法或需要更多信息,我们将不胜感激。