XMl 代码

-------------------------------------------------------------------------------------------------------------------------------

<UserControl

x:Class="Xiaowei.Controls.PermissionBlock"

xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"

xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"

xmlns:local="using:Xiaowei.Controls"

xmlns:d="http://schemas.microsoft.com/expression/blend/2008"

xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"

xmlns:tk="using:Microsoft.Toolkit.Uwp.UI.Controls"

mc:Ignorable="d"

d:DesignHeight="200"

d:DesignWidth="480"

Height="76"

x:Name="permissionBlock">

<UserControl.Resources>

<Storyboard x:Name="GIFStoryBoard">

<DoubleAnimation

x:Name="GIFDoubleAnimation"

EnableDependentAnimation="True"

To="176" Duration="00:00:0.3"

Storyboard.TargetName="borderGrid"

Storyboard.TargetProperty="Height">

<DoubleAnimation.EasingFunction>

<PowerEase EasingMode="EaseInOut"/>

</DoubleAnimation.EasingFunction>

</DoubleAnimation>

<DoubleAnimation

x:Name="GIFBorderDoubleAnimation"

EnableDependentAnimation="True"

To="1" Duration="00:00:0.3"

Storyboard.TargetName="shadowBorder"

Storyboard.TargetProperty="Opacity">

<DoubleAnimation.EasingFunction>

<PowerEase EasingMode="EaseInOut"/>

</DoubleAnimation.EasingFunction>

</DoubleAnimation>

</Storyboard>

</UserControl.Resources>

<Grid x:Name="borderGrid" Height="76" VerticalAlignment="Top" Margin="0,0,0,-200">

<tk:DropShadowPanel Opacity="0"

x:Name="shadowBorder"

VerticalContentAlignment="Stretch"

Margin="14,0,14,8"

HorizontalContentAlignment="Stretch">

<Grid Background="White"

CornerRadius="7" >

</Grid>

</tk:DropShadowPanel>

<Grid Background="White" CornerRadius="7" Margin="14,0,14,8" VerticalAlignment="Stretch" PointerEntered="PointerEntered" PointerExited="PointerExited">

<Grid.RowDefinitions>

<RowDefinition Height="auto"/>

<RowDefinition Height="1*"/>

</Grid.RowDefinitions>

<Image

Width="28"

Height="28"

Margin="12,20,0,20"

HorizontalAlignment="Left"

VerticalAlignment="Center"

Source="{Binding Icon, ElementName=permissionBlock, Mode=OneWay}"

/>

<TextBlock

HorizontalAlignment="Left"

VerticalAlignment="Top"

FontSize="16"

Foreground="#272727"

Margin="48,12,0,0"

Text="{Binding Title, ElementName=permissionBlock, Mode=OneWay}">

</TextBlock>

<TextBlock

Foreground="#666666"

HorizontalAlignment="Left"

VerticalAlignment="Bottom"

FontSize="14"

FontWeight="Light"

Text="{Binding Comment, ElementName=permissionBlock, Mode=OneWay}"

Margin="48,0,0,11">

</TextBlock>

<Button

Style="{ThemeResource ButtonStyleTransBack}"

Content="开启"

Click="ActiveButton_Click"

HorizontalAlignment="Right"

Margin="0,0,25,0"

Foreground="#4367FC"

FontSize="16"/>

<Image

Grid.Row="1" Height="119" Margin="12,0,12,12"

Source="{Binding GIFSource, ElementName=permissionBlock, Mode=OneWay}"

/>

</Grid>

</Grid>

</UserControl>

C# code

-----------------------------------------------------------------------------------------------------------------------------------

using System;

using Windows.UI;

using Windows.UI.Xaml;

using Windows.UI.Xaml.Controls;

using Windows.UI.Xaml.Media;

// The User Control item template is documented at https://go.microsoft.com/fwlink/?LinkId=234236

namespace Xiaowei.Controls

{

public sealed partial class PermissionBlock : UserControl

{

public static DependencyProperty TitleProperty { get; } = DependencyProperty.Register(

"Title", typeof(string), typeof(PermissionBlock), new PropertyMetadata("")

);

public string Title

{

get

{

return (string)GetValue(TitleProperty);

}

set

{

SetValue(TitleProperty, value);

}

}

public static DependencyProperty CommentProperty { get; } = DependencyProperty.Register(

"Comment", typeof(string), typeof(PermissionBlock), new PropertyMetadata("")

);

public string Comment

{

get

{

return (string)GetValue(CommentProperty);

}

set

{

SetValue(CommentProperty, value);

}

}

public static DependencyProperty IconProperty { get; } = DependencyProperty.Register(

"Icon", typeof(ImageSource), typeof(PermissionBlock), new PropertyMetadata(null)

);

public ImageSource Icon

{

get

{

return (ImageSource)GetValue(IconProperty);

}

set

{

SetValue(IconProperty, value);

}

}

public static DependencyProperty GIFSourceProperty { get; } = DependencyProperty.Register(

"GIFSource", typeof(ImageSource), typeof(PermissionBlock), new PropertyMetadata(null)

);

public ImageSource GIFSource

{

get

{

return (ImageSource)GetValue(GIFSourceProperty);

}

set

{

SetValue(GIFSourceProperty, value);

}

}

private void ShowGif()

{

GIFDoubleAnimation.To = 210;

GIFBorderDoubleAnimation.To = 1;

GIFStoryBoard.Begin();

}

private void HideGif()

{

GIFDoubleAnimation.To = 76;

GIFBorderDoubleAnimation.To = 0;

GIFStoryBoard.Begin();

}

public static DependencyProperty IsAllowProperty { get; } = DependencyProperty.Register(

"IsAllow", typeof(bool), typeof(PermissionBlock), new PropertyMetadata(false, IsAllowPropertyChanged)

);

private static void IsAllowPropertyChanged(DependencyObject d, DependencyPropertyChangedEventArgs e)

{

if ((bool)e.NewValue)

{

((PermissionBlock)d).Hide();

}

else

{

((PermissionBlock)d).Show();

}

}

public bool IsAllow

{

get

{

return (bool)GetValue(IsAllowProperty);

}

set

{

SetValue(IsAllowProperty, value);

}

}

private void Show()

{

Visibility = Visibility.Visible;

}

private void Hide()

{

Visibility = Visibility.Collapsed;

HideGif();

}

public PermissionBlock()

{

this.InitializeComponent();

}

public event Action Click;

private void ActiveButton_Click(object sender, RoutedEventArgs e)

{

Click?.Invoke();

}

private void PointerEntered(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)

{

ShowGif();

}

private void PointerExited(object sender, Windows.UI.Xaml.Input.PointerRoutedEventArgs e)

{

HideGif();

}

}

}

wpf 中的 自定义控件的 binding的更多相关文章

  1. WPF中关于自定义控件的滚动条鼠标停留在内容上鼠标滚轮滚动无效的问题

    问题起因:在一个用户控件里放置了1个TreeView垂直顺序放置. 当用户控件中的内容超过面板大小时,滚动条会自动出现 ,但是只有当鼠标指示在右边滚动条的那一条位置时,才支持鼠标滚轴滚动. 点在控件内 ...

  2. WPF中的数据绑定Data Binding使用小结

    完整的数据绑定的语法说明可以在这里查看: http://www.nbdtech.com/Free/WpfBinding.pdf MSDN资料: Data Binding: Part 1 http:// ...

  3. 在WPF中自定义控件

    一, 不一定需要自定义控件在使用WPF以前,动辄使用自定义控件几乎成了惯性思维,比如需要一个带图片的按钮,但在WPF中此类任务却不需要如此大费周章,因为控件可以嵌套使用以及可以为控件外观打造一套新的样 ...

  4. 【转】WPF中Binding的技巧(一)

    WPF中Binding的技巧(一)   在WPF应用的开发过程中Binding是一个非常重要的部分. 在实际开发过程中Binding的不同种写法达到的效果相同但事实是存在很大区别的. 这里将实际中碰到 ...

  5. 【转】WPF中的Binding技巧(二)

    WPF中的Binding技巧(二)     接上篇, 我们来看一看Elementname,Source,RelativeSource 三种绑定的方式 1.ElementName顾名思义就是根据Ui元素 ...

  6. Binding在WPF中的使用

    闲来无事,不想打DOTA,在这里小小研究下wpf中关于Binding的东西. 咯咯 在我们印象中,Binding的意思是“绑定”,这个“绑”大概取自于Bind这个单词吧,这么理解的话就是以音译英了,没 ...

  7. WPF中添加Winform用户自定义控件

    过程:创建WPF工程->创建Winform用户自定义控件工程->WPF中引用控件->添加到Xaml页面 1.首先在WPF工程的解决方案上右击选择添加新建项目: 选择Windows窗体 ...

  8. WPF binding<一> Data Binding在WPF中的地位

    在代码中看到 <Image Source="{Binding ElementName=LBoxImages, Path=SelectedItem.Source}" /> ...

  9. 在WPF中自定义控件(3) CustomControl (上)

    原文:在WPF中自定义控件(3) CustomControl (上) 在WPF中自定义控件(3) CustomControl (上)                              周银辉 ...

随机推荐

  1. Pandas高级教程之:window操作

    目录 简介 滚动窗口 Center window Weighted window 加权窗口 扩展窗口 指数加权窗口 简介 在数据统计中,经常需要进行一些范围操作,这些范围我们可以称之为一个window ...

  2. 学习 CLR 源码:连续内存块数据操作的性能优化

    目录 C# 原语类型 1,利用 Buffer 优化数组性能 2,BinaryPrimitives 细粒度操作字节数组 提高代码安全性 3,BitConverter.MemoryMarshal 4,Ma ...

  3. Linux虚拟机扩展磁盘

    Linux虚拟机扩展磁盘 1.虚拟机关机,Vmware中扩展磁盘 2.虚拟机开机,查看磁盘大小 [root@hadoop6 ~]# df -h 文件系统 容量 已用 可用 已用% 挂载点 devtmp ...

  4. 数据结构算法学习之队列(数组模拟java实现)

    数组模拟队列 数组模拟队列 今天学习数组模拟队列.队列常用于生活中的方方面面.比如银行叫号排队.实际上就是队列.所有人抽号排队.先去的先抽号.所以靠前的号最后会先被叫到然后出队.后边的会随之往前移位. ...

  5. http request 请求拦截器,有token值则配置上token值

    // http request 请求拦截器,有token值则配置上token值 axios.interceptors.request.use( config => { if (token) { ...

  6. 来看看是什么原因导致生产服上的系统CPU高的?

    我们可能会遇到生产服务器CPU很高的问题,有时候能确定是哪个进程,但是不知道这个进程都在干什么,所以也无从下手,无法解决问题.只能不断的重启,重启等. 最近也看了[一线码农]的一些教程,觉得都很不错, ...

  7. 【LeetCode】155. 最小栈

    155. 最小栈 知识点:栈:单调 题目描述 设计一个支持 push ,pop ,top 操作,并能在常数时间内检索到最小元素的栈. push(x) -- 将元素 x 推入栈中. pop() -- 删 ...

  8. 记一次mysql事务未提交导致锁未释放的问题

    记一次mysql事务未提交导致锁未释放的问题 ## 查看未提交的事务(3秒内未操作的事务) SELECT p.ID AS conn_id, P.USER AS login_user, P.HOST A ...

  9. Linux命令(三)vim编辑器的常用命令

    .subTitle { background: rgba(51, 153, 0, 0.53); border-bottom: 1px solid rgba(0, 102, 0, 1); border- ...

  10. java常见面试题总结2

    JAVA必背面试题和项目面试通关要点 简单来讲,equals方法主要是用来判断从表面上看或者从内容上看,2个对象是不是相等. 一 数据库 1.常问数据库查询.修改(SQL查询包含筛选查询.聚合查询和链 ...