【WPF】 使用UserControl并在XAML中赋初始值


一、前言

在XAML中使用自定义控件,并在XAML中并赋初始值。

二、使用步骤

1. cs中设置控件属性

设置OriginLocation,ScaleInterval 属性,可以通过XAML内传初始值

using System.Windows;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows.Shapes;

public partial class RadarChart : UserControl
{

    //原点位置
    private static readonly DependencyProperty OriginLocationProperty =
        DependencyProperty.Register("OriginLocation", typeof(string), typeof(RadarChart));
    //刻度间隔
    private static readonly DependencyProperty ScaleIntervalProperty =
        DependencyProperty.Register("ScaleInterval",typeof(int),typeof(RadarChart));
    
    
    


    public string OriginLocation {
        get { return (string)GetValue(OriginLocationProperty); }
        set { SetValue(OriginLocationProperty, value); }
    }

    public int ScaleInterval {
        get { return (int)GetValue(ScaleIntervalProperty); }
        set { SetValue(ScaleIntervalProperty, value); }
    }
 }   

2. 在引入控件时,Xaml传初始值

<components:RadarChart OriginLocation="upleft" ScaleInterval="10" />

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值