add ImageAttach
This commit is contained in:
1 parent
8e34fc1d29
commit
d9959fab38
21 files changed
+131
-50
No files matched your search
@@ -0,0 +1,42 @@
|
||||
using System.Windows;
|
||||
using System.Windows.Controls;
|
||||
using System.Windows.Media;
|
||||
|
||||
namespace HandyControl.Controls
|
||||
{
|
||||
public class ImageAttach
|
||||
{
|
||||
public static readonly DependencyProperty SourceFailedProperty = DependencyProperty.RegisterAttached(
|
||||
"SourceFailed", typeof(ImageSource), typeof(ImageAttach), new FrameworkPropertyMetadata(default(ImageSource), FrameworkPropertyMetadataOptions.Inherits, OnSourceFailedChanged));
|
||||
|
||||
private static void OnSourceFailedChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)
|
||||
{
|
||||
if (d is Image image)
|
||||
{
|
||||
if (e.NewValue is ImageSource)
|
||||
{
|
||||
image.ImageFailed += Image_ImageFailed;
|
||||
}
|
||||
else
|
||||
{
|
||||
image.ImageFailed -= Image_ImageFailed;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private static void Image_ImageFailed(object sender, ExceptionRoutedEventArgs e)
|
||||
{
|
||||
if (sender is Image image)
|
||||
{
|
||||
image.SetCurrentValue(Image.SourceProperty, GetSourceFailed(image));
|
||||
image.ImageFailed -= Image_ImageFailed;
|
||||
}
|
||||
}
|
||||
|
||||
public static void SetSourceFailed(DependencyObject element, ImageSource value)
|
||||
=> element.SetValue(SourceFailedProperty, value);
|
||||
|
||||
public static ImageSource GetSourceFailed(DependencyObject element)
|
||||
=> (ImageSource) element.GetValue(SourceFailedProperty);
|
||||
}
|
||||
}
|
||||
@@ -8,9 +8,6 @@ namespace HandyControl.Controls
|
||||
/// <summary>
|
||||
/// 切换块
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// 在不需要命中测试的情况下可代替ToggleButton或CheckBox,以减少内存用量。
|
||||
/// </remarks>
|
||||
public class ToggleBlock : Control
|
||||
{
|
||||
public static readonly DependencyProperty IsCheckedProperty = DependencyProperty.Register(
|
||||
|
||||
@@ -17,6 +17,7 @@
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Attach\EdgeElement.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Attach\IconElement.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Attach\IconSwitchElement.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Attach\ImageAttach.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Attach\InfoElement.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Attach\MenuTopLineAttach.cs" />
|
||||
<Compile Include="$(MSBuildThisFileDirectory)Controls\Attach\PanelElement.cs" />
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
xmlns:controls="clr-namespace:HandyControl.Controls">
|
||||
|
||||
<Style x:Key="ToggleBlockBaseStyle" TargetType="controls:ToggleBlock">
|
||||
<Setter Property="IsHitTestVisible" Value="False"/>
|
||||
<Setter Property="VerticalContentAlignment" Value="Center"/>
|
||||
<Setter Property="HorizontalContentAlignment" Value="Center"/>
|
||||
<Setter Property="Template">
|
||||
@@ -19,11 +18,17 @@
|
||||
<ControlTemplate.Triggers>
|
||||
<Trigger Property="IsChecked" Value="True">
|
||||
<Setter TargetName="ContentPresenterChecked" Property="Visibility" Value="Visible"/>
|
||||
<Setter TargetName="ContentPresenterUnChecked" Property="Visibility" Value="Collapsed"/>
|
||||
<Setter TargetName="ContentPresenterIndeterminate" Property="Visibility" Value="Collapsed"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsChecked" Value="False">
|
||||
<Setter TargetName="ContentPresenterChecked" Property="Visibility" Value="Collapsed"/>
|
||||
<Setter TargetName="ContentPresenterUnChecked" Property="Visibility" Value="Visible"/>
|
||||
<Setter TargetName="ContentPresenterIndeterminate" Property="Visibility" Value="Collapsed"/>
|
||||
</Trigger>
|
||||
<Trigger Property="IsChecked" Value="{x:Null}">
|
||||
<Setter TargetName="ContentPresenterChecked" Property="Visibility" Value="Collapsed"/>
|
||||
<Setter TargetName="ContentPresenterUnChecked" Property="Visibility" Value="Collapsed"/>
|
||||
<Setter TargetName="ContentPresenterIndeterminate" Property="Visibility" Value="Visible"/>
|
||||
</Trigger>
|
||||
</ControlTemplate.Triggers>
|
||||
|
||||
Reference in new issue
Block a user