add ImageAttach

This commit is contained in:
NaBian committed 2020-06-06 23:23:40 +08:00
1 parent 8e34fc1d29
commit d9959fab38
21 files changed
+131 -50

No files matched your search

@@ -49,6 +49,9 @@
<Resource Include="..\..\Shared\HandyControlDemo_Shared\Data\DemoInfo.json">
<Link>Data\DemoInfo.json</Link>
</Resource>
<Resource Include="..\..\Shared\HandyControlDemo_Shared\Resources\Img\chrome_dragon.png">
<Link>Resources\Img\chrome_dragon.png</Link>
</Resource>
<Resource Include="..\..\Shared\HandyControlDemo_Shared\Resources\Img\Cover.png">
<Link>Resources\Img\Cover.png</Link>
</Resource>
@@ -49,6 +49,9 @@
<Resource Include="..\..\Shared\HandyControlDemo_Shared\Data\DemoInfo.json">
<Link>Data\DemoInfo.json</Link>
</Resource>
<Resource Include="..\..\Shared\HandyControlDemo_Shared\Resources\Img\chrome_dragon.png">
<Link>Resources\Img\chrome_dragon.png</Link>
</Resource>
<Resource Include="..\..\Shared\HandyControlDemo_Shared\Resources\Img\Cover.png">
<Link>Resources\Img\Cover.png</Link>
</Resource>
Binary file not shown.

After

Width:  |  Height:  |  Size: 1.9 KiB

@@ -129,10 +129,11 @@ namespace HandyControlDemo.Service
Link = item.html_url
}));
}
catch
catch(Exception e)
{
// ignored
HandyControl.Controls.MessageBox.Error(e.Message, Lang.Error);
}
return list;
}
@@ -180,7 +181,7 @@ namespace HandyControlDemo.Service
new AvatarModel
{
DisplayName = "AutumnBox",
AvatarUri = "https://www.atmb.top/images/leaves.png",
AvatarUri = "https://raw.githubusercontent.com/zsh2401/AutumnBox/master/src/AutumnBox.GUI/Resources/Images/icon.png",
Link = "https://github.com/zsh2401/AutumnBox"
}
};
@@ -15,7 +15,7 @@
<RowDefinition/>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<Image Source="{Binding Source,RelativeSource={RelativeSource AncestorType=UserControl}}" Height="120" Width="120" Stretch="Uniform" Margin="10"/>
<Image hc:ImageAttach.SourceFailed="/Resources/Img/chrome_dragon.png" Source="{Binding Source,RelativeSource={RelativeSource AncestorType=UserControl}}" Height="120" Width="120" Stretch="Uniform" Margin="10"/>
<TextBlock TextTrimming="CharacterEllipsis" TextWrapping="NoWrap" Margin="0,0,0,10" Grid.Row="1" Style="{StaticResource TextBlockDefault}" Text="{Binding DisplayName,RelativeSource={RelativeSource AncestorType=UserControl}}"/>
</Grid>
</Border>
@@ -10,7 +10,7 @@
<hc:OutlineText TextWrapping="Wrap" Fill="{DynamicResource PrimaryTextBrush}" Text="{ex:Lang Key={x:Static langs:LangKeys.Text}, Converter={StaticResource StringRepeatConverter}, ConverterParameter=20}"/>
<hc:OutlineText Margin="0,10,0,0" FontSize="30" Fill="{DynamicResource SuccessBrush}" Text="{ex:Lang Key={x:Static langs:LangKeys.Text}, Converter={StaticResource StringRepeatConverter}, ConverterParameter=8}"/>
<hc:OutlineText Margin="0,10,0,0" Fill="{DynamicResource PrimaryTextBrush}" FontSize="30" FontStyle="Italic" Text="{ex:Lang Key={x:Static langs:LangKeys.Text}, Converter={StaticResource StringRepeatConverter}, ConverterParameter=8}"/>
<hc:OutlineText Margin="0,10,0,0" TextWrapping="Wrap" TextTrimming="CharacterEllipsis" FontSize="50" StrokeThickness="2" Fill="{DynamicResource DangerBrush}" Stroke="{DynamicResource PrimaryBrush}" Text="ex:Lang Key={x:Static langs:LangKeys.Text}, Converter={StaticResource StringRepeatConverter}, ConverterParameter=5}"/>
<hc:OutlineText Margin="0,10,0,0" TextWrapping="Wrap" TextTrimming="CharacterEllipsis" FontSize="50" StrokeThickness="2" Fill="{DynamicResource DangerBrush}" Stroke="{DynamicResource PrimaryBrush}" Text="{ex:Lang Key={x:Static langs:LangKeys.Text}, Converter={StaticResource StringRepeatConverter}, ConverterParameter=5}"/>
<hc:OutlineText Margin="0,10,0,0" FontSize="80" FontWeight="Bold" StrokeThickness="4" Fill="{DynamicResource PrimaryBrush}" Stroke="{DynamicResource DangerBrush}" Text="{ex:Lang Key={x:Static langs:LangKeys.Text}, Converter={StaticResource StringRepeatConverter}, ConverterParameter=2}"/>
<hc:OutlineText Margin="0,10,0,0" StrokePosition="Outside" FontSize="80" FontWeight="Bold" StrokeThickness="4" Fill="{DynamicResource PrimaryBrush}" Stroke="{DynamicResource DangerBrush}" Text="{ex:Lang Key={x:Static langs:LangKeys.Text}, Converter={StaticResource StringRepeatConverter}, ConverterParameter=2}"/>
<hc:OutlineText Margin="0,10,0,0" StrokePosition="InSide" FontSize="80" FontWeight="Bold" StrokeThickness="4" Fill="{DynamicResource PrimaryBrush}" Stroke="{DynamicResource DangerBrush}" Text="{ex:Lang Key={x:Static langs:LangKeys.Text}, Converter={StaticResource StringRepeatConverter}, ConverterParameter=2}"/>
@@ -5,7 +5,7 @@
xmlns:hc="https://handyorg.github.io/handycontrol"
DataContext="{Binding BlogsView,Source={StaticResource Locator}}"
Background="{DynamicResource SecondaryRegionBrush}">
<hc:Watermark Mark="Blog" FontSize="80" MarkMargin="30,0">
<hc:Watermark Mark="Blog" FontSize="80" FontWeight="Bold" MarkMargin="30,0">
<ListBox Background="Transparent" ItemContainerStyle="{StaticResource ListBoxItemCustom}" BorderThickness="0" ItemsSource="{Binding DataList}" ItemsPanel="{StaticResource FluidMoveBehaviorWrapPanelItemsPanelTemplate}">
<ListBox.ItemTemplate>
<DataTemplate>
@@ -5,13 +5,20 @@
xmlns:hc="https://handyorg.github.io/handycontrol"
DataContext="{Binding ContributorsView,Source={StaticResource Locator}}"
Background="{DynamicResource SecondaryRegionBrush}">
<hc:Watermark Mark="{StaticResource GitHubStrGeometry}" MarkMargin="30,0" MarkWidth="200" MarkHeight="100">
<ListBox Background="Transparent" ItemContainerStyle="{StaticResource ListBoxItemCustom}" BorderThickness="0" ItemsSource="{Binding DataList}" ItemsPanel="{StaticResource FluidMoveBehaviorWrapPanelItemsPanelTemplate}">
<ListBox.ItemTemplate>
<DataTemplate>
<userControl:Avatar DisplayName="{Binding DisplayName}" Link="{Binding Link}" Source="{Binding AvatarUri}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<hc:Watermark FontWeight="Bold" Mark="{StaticResource GitHubStrGeometry}" MarkMargin="30,0" MarkWidth="200" MarkHeight="100">
<hc:ToggleBlock IsChecked="{Binding DataGot}" VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch">
<hc:ToggleBlock.UnCheckedContent>
<hc:LoadingCircle IsRunning="{Binding DataGot,Converter={StaticResource Boolean2BooleanReConverter}}"/>
</hc:ToggleBlock.UnCheckedContent>
<hc:ToggleBlock.CheckedContent>
<ListBox Background="Transparent" ItemContainerStyle="{StaticResource ListBoxItemCustom}" BorderThickness="0" ItemsSource="{Binding DataList}" ItemsPanel="{StaticResource FluidMoveBehaviorWrapPanelItemsPanelTemplate}">
<ListBox.ItemTemplate>
<DataTemplate>
<userControl:Avatar DisplayName="{Binding DisplayName}" Link="{Binding Link}" Source="{Binding AvatarUri}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</hc:ToggleBlock.CheckedContent>
</hc:ToggleBlock>
</hc:Watermark>
</UserControl>
@@ -6,7 +6,7 @@
xmlns:langs="clr-namespace:HandyControlDemo.Properties.Langs"
xmlns:ex="clr-namespace:HandyControlDemo.Tools.Extension"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
Margin="16"
Margin="16,16,0,16"
CornerRadius="10"
Effect="{StaticResource EffectShadow4}">
<Border.Resources>
@@ -2,23 +2,28 @@
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:hc="https://handyorg.github.io/handycontrol"
x:Class="HandyControlDemo.UserControl.MainContent">
<Grid Name="GridMain" MinHeight="300" MinWidth="200" HorizontalAlignment="Center" VerticalAlignment="Center" Margin="16">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Border Name="BorderEffect" Grid.RowSpan="2" Background="{DynamicResource RegionBrush}" CornerRadius="10" Effect="{StaticResource EffectShadow4}"/>
<Border Height="32" Name="BorderTitle" Grid.Row="0" CornerRadius="10,10,0,0" Background="{DynamicResource TitleBrush}">
<hc:SimplePanel>
<TextBlock Style="{StaticResource TextBlockDefault}" Foreground="White" Text="{Binding ContentTitle}"/>
<ToggleButton Margin="0,0,6,0" IsChecked="{Binding IsOpen,ElementName=DrawerCode}" Padding="5" Foreground="{DynamicResource TextIconBrush}" Style="{StaticResource ToggleButtonIconTransparent}" HorizontalAlignment="Right" hc:IconElement.Geometry="{StaticResource CodeGeometry}"/>
<hc:Drawer Name="DrawerCode" Opened="DrawerCode_OnOpened">
<Border Style="{StaticResource BorderClip}" Margin="32,32,0,32" CornerRadius="10,0,0,10" Background="{DynamicResource RegionBrush}" Width="800" Name="BorderCode"/>
</hc:Drawer>
</hc:SimplePanel>
<hc:SimplePanel>
<Border Name="BorderRootEffect" Background="{DynamicResource RegionBrush}" CornerRadius="10" Effect="{StaticResource EffectShadow4}" Margin="16" Visibility="Collapsed"/>
<Border Name="BorderRoot" Style="{StaticResource BorderClip}" Margin="16">
<Grid Name="GridMain" MinHeight="300" MinWidth="200" HorizontalAlignment="Center" VerticalAlignment="Center">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition/>
</Grid.RowDefinitions>
<Border Name="BorderEffect" Grid.RowSpan="2" Background="{DynamicResource RegionBrush}" CornerRadius="10" Effect="{StaticResource EffectShadow4}"/>
<Border Height="32" Name="BorderTitle" Grid.Row="0" CornerRadius="10,10,0,0" Background="{DynamicResource TitleBrush}">
<hc:SimplePanel>
<TextBlock Style="{StaticResource TextBlockDefault}" Foreground="White" Text="{Binding ContentTitle}"/>
<ToggleButton Margin="0,0,6,0" IsChecked="{Binding IsOpen,ElementName=DrawerCode}" Padding="5" Foreground="{DynamicResource TextIconBrush}" Style="{StaticResource ToggleButtonIconTransparent}" HorizontalAlignment="Right" hc:IconElement.Geometry="{StaticResource CodeGeometry}"/>
<hc:Drawer Name="DrawerCode" Opened="DrawerCode_OnOpened">
<Border Style="{StaticResource BorderClip}" Margin="32,32,0,32" CornerRadius="10,0,0,10" Background="{DynamicResource RegionBrush}" Width="800" Name="BorderCode"/>
</hc:Drawer>
</hc:SimplePanel>
</Border>
<Border Grid.Row="1" ClipToBounds="True">
<ContentPresenter Name="PresenterMain" Margin="0,0,0,10" Content="{Binding SubContent}"/>
</Border>
</Grid>
</Border>
<Border Grid.Row="1" ClipToBounds="True">
<ContentPresenter Name="PresenterMain" Margin="0,0,0,10" Content="{Binding SubContent}"/>
</Border>
</Grid>
</hc:SimplePanel>
</Border>
@@ -38,21 +38,25 @@ namespace HandyControlDemo.UserControl
_isFull = isFull;
if (_isFull)
{
BorderRootEffect.Show();
BorderEffect.Collapse();
BorderTitle.Collapse();
GridMain.HorizontalAlignment = HorizontalAlignment.Stretch;
GridMain.VerticalAlignment = VerticalAlignment.Stretch;
GridMain.Margin = new Thickness();
PresenterMain.Margin = new Thickness();
BorderRoot.CornerRadius = new CornerRadius(10);
BorderRoot.Style = ResourceHelper.GetResource<Style>("BorderClip");
}
else
{
BorderRootEffect.Collapse();
BorderEffect.Show();
BorderTitle.Show();
GridMain.HorizontalAlignment = HorizontalAlignment.Center;
GridMain.VerticalAlignment = VerticalAlignment.Center;
GridMain.Margin = new Thickness(16);
PresenterMain.Margin = new Thickness(0, 0, 0, 10);
BorderRoot.CornerRadius = new CornerRadius();
BorderRoot.Style = null;
}
}
@@ -3,6 +3,8 @@
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008">
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:userControl="clr-namespace:HandyControlDemo.UserControl"
Background="{DynamicResource SecondaryRegionBrush}">
<userControl:UnderConstruction VerticalAlignment="Center" HorizontalAlignment="Center"/>
</UserControl>
@@ -5,7 +5,7 @@
xmlns:hc="https://handyorg.github.io/handycontrol"
DataContext="{Binding ProjectsView,Source={StaticResource Locator}}"
Background="{DynamicResource SecondaryRegionBrush}">
<hc:Watermark Mark="Project" FontSize="80" MarkMargin="30,0">
<hc:Watermark Mark="Project" FontSize="80" FontWeight="Bold" MarkMargin="30,0">
<ListBox Background="Transparent" ItemContainerStyle="{StaticResource ListBoxItemCustom}" BorderThickness="0" ItemsSource="{Binding DataList}" ItemsPanel="{StaticResource FluidMoveBehaviorWrapPanelItemsPanelTemplate}">
<ListBox.ItemTemplate>
<DataTemplate>
@@ -5,7 +5,7 @@
xmlns:hc="https://handyorg.github.io/handycontrol"
DataContext="{Binding WebsitesView,Source={StaticResource Locator}}"
Background="{DynamicResource SecondaryRegionBrush}">
<hc:Watermark Mark="Website" FontSize="80" MarkMargin="30,0">
<hc:Watermark Mark="Website" FontSize="80" FontWeight="Bold" MarkMargin="30,0">
<ListBox Background="Transparent" ItemContainerStyle="{StaticResource ListBoxItemCustom}" BorderThickness="0" ItemsSource="{Binding DataList}" ItemsPanel="{StaticResource FluidMoveBehaviorWrapPanelItemsPanelTemplate}">
<ListBox.ItemTemplate>
<DataTemplate>
@@ -7,12 +7,24 @@ namespace HandyControlDemo.ViewModel
{
public class ItemsDisplayViewModel : DemoViewModelBase<AvatarModel>
{
public ItemsDisplayViewModel(Func<List<AvatarModel>> getDatAction)
public ItemsDisplayViewModel(Func<List<AvatarModel>> getDataAction)
{
#if NET40
Task.Factory.StartNew(() => DataList = getDatAction?.Invoke());
#if !NET40
Task.Factory.StartNew(() => DataList = getDataAction?.Invoke()).ContinueWith(obj => DataGot = true);
#else
Task.Run(() => DataList = getDatAction?.Invoke());
Task.Run(() => DataList = getDataAction?.Invoke()).ContinueWith(obj => DataGot = true);
#endif
}
private bool _dataGot;
public bool DataGot
{
get => _dataGot;
#if NET40
set => Set(nameof(DataGot), ref _dataGot, value);
#else
set => Set(ref _dataGot, value);
#endif
}
}
@@ -176,8 +176,8 @@ namespace HandyControlDemo.ViewModel
private void OpenPracticalDemo()
{
Messenger.Default.Send<object>(null, MessageToken.ClearLeftSelected);
Messenger.Default.Send(true, MessageToken.FullSwitch);
Messenger.Default.Send(AssemblyHelper.CreateInternalInstance($"UserControl.{MessageToken.PracticalDemo}"), MessageToken.LoadShowContent);
Messenger.Default.Send(true, MessageToken.FullSwitch);
}
#endregion
@@ -19,7 +19,6 @@ namespace HandyControlDemo.ViewModel
SimpleIoc.Default.Register<ImageBrowserDemoViewModel>();
SimpleIoc.Default.Register<ComboBoxDemoViewModel>();
SimpleIoc.Default.Register<WindowDemoViewModel>();
SimpleIoc.Default.Register(() => new ItemsDisplayViewModel(dataService.GetContributorDataList), "Contributors");
SimpleIoc.Default.Register(() => new ItemsDisplayViewModel(dataService.GetBlogDataList), "Blogs");
SimpleIoc.Default.Register(() => new ItemsDisplayViewModel(dataService.GetProjectDataList), "Projects");
SimpleIoc.Default.Register(() => new ItemsDisplayViewModel(dataService.GetWebsiteDataList), "Websites");
@@ -58,7 +57,7 @@ namespace HandyControlDemo.ViewModel
public WindowDemoViewModel WindowDemo => SimpleIoc.Default.GetInstance<WindowDemoViewModel>();
public ItemsDisplayViewModel ContributorsView => SimpleIoc.Default.GetInstance<ItemsDisplayViewModel>("Contributors");
public ItemsDisplayViewModel ContributorsView => new ItemsDisplayViewModel(SimpleIoc.Default.GetInstance<DataService>().GetContributorDataList);
public ItemsDisplayViewModel BlogsView => SimpleIoc.Default.GetInstance<ItemsDisplayViewModel>("Blogs");
@@ -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>