国产 无码 综合区,色欲AV无码国产永久播放,无码天堂亚洲国产AV,国产日韩欧美女同一区二区

WPF 控件 (四、單選按鈕)

這篇具有很好參考價值的文章主要介紹了WPF 控件 (四、單選按鈕)。希望對大家有所幫助。如果存在錯誤或未考慮完全的地方,請大家不吝賜教,您也可以點擊"舉報違法"按鈕提交疑問。

一、選中顯示下劃線

1. style

 <Style x:Key="UnderlineRadioButton" TargetType="RadioButton">
        <Setter Property="Width" Value="50"/>
        <Setter Property="Height" Value="30"/>
        <Setter Property="Cursor" Value="Hand"/>
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="RadioButton">
                    <Border Background="Transparent" Width="{TemplateBinding Width}" Height="{TemplateBinding Height}">
                        <StackPanel>
                            <Border Background="{TemplateBinding Background}" CornerRadius="10" Width="{TemplateBinding Width}" Height="20">
                                <ContentPresenter x:Name="contentPresenter" RecognizesAccessKey="True" VerticalAlignment="Center" HorizontalAlignment="Center" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                            </Border>
                            <Line X1="0" Y1="0" X2="{TemplateBinding Width}" Y2="0" Margin="0,5" x:Name="line1" Stroke="{TemplateBinding Foreground}" StrokeThickness="1"/>
                        </StackPanel>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsChecked" Value="True">
                            <Setter TargetName="line1" Property="Visibility" Value="Visible"/>
                        </Trigger>
                        <Trigger Property="IsChecked" Value="False">
                            <Setter TargetName="line1" Property="Visibility" Value="Collapsed"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <Trigger Property="IsChecked" Value="True">
                <Setter Property="Opacity" Value="0.8"/>
            </Trigger>
        </Style.Triggers>
    </Style>

2.demo

 <WrapPanel Margin="0,10">
    <RadioButton Content="rb1"  Style="{StaticResource UnderlineRadioButton}"  Background="Black" Foreground="Blue"/>
    <RadioButton Content="rb2"  Style="{StaticResource UnderlineRadioButton}"  Background="Black" Foreground="Red"/>
    <RadioButton Content="rb3"  Style="{StaticResource UnderlineRadioButton}"  Background="Black" Foreground="Green"/>
    <RadioButton Content="rb4"  Style="{StaticResource UnderlineRadioButton}"  Background="Black" Foreground="Yellow"/>
    <RadioButton Content="rb5"  Style="{StaticResource UnderlineRadioButton}"  Background="Black" Foreground="Purple"/>
</WrapPanel>

3.效果

wpf 單選框,wpf,ui,c#
wpf 單選框,wpf,ui,c#
wpf 單選框,wpf,ui,c#

二、帶圖標(biāo)的單選按鈕

1. RadioButton2

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Controls;
using System.Windows.Media;
using System.Windows;

namespace lyrics.ui.Controls.ButtonCustom
{
    internal class RadioButton2 : RadioButton
    {
        static RadioButton2()
        {
            DefaultStyleKeyProperty.OverrideMetadata(typeof(RadioButton2), new FrameworkPropertyMetadata(typeof(RadioButton2)));
        }

        #region Icon 
        public static readonly DependencyProperty IconProperty =
            DependencyProperty.Register("Icon", typeof(Geometry), typeof(RadioButton2), new PropertyMetadata(default(Geometry)));

        public Geometry Icon
        {
            get => (Geometry)GetValue(IconProperty);
            set => SetValue(IconProperty, value);
        }
        public static readonly DependencyProperty Icon2Property =
    DependencyProperty.Register("Icon2", typeof(Geometry), typeof(RadioButton2), new PropertyMetadata(default(Geometry)));

        public Geometry Icon2
        {
            get => (Geometry)GetValue(Icon2Property);
            set => SetValue(Icon2Property, value);
        }
        public static readonly DependencyProperty IconWidthProperty =
    DependencyProperty.Register("IconWidth", typeof(double), typeof(RadioButton2), new PropertyMetadata(default(double)));

        public double IconWidth
        {
            get => (double)GetValue(IconWidthProperty);
            set => SetValue(IconWidthProperty, value);
        }

        public static readonly DependencyProperty IconHeightProperty =
DependencyProperty.Register("IconHeight", typeof(double), typeof(RadioButton2), new PropertyMetadata(default(double)));

        public double IconHeight
        {
            get => (double)GetValue(IconHeightProperty);
            set => SetValue(IconHeightProperty, value);
        }
        #endregion
    }
}

2. Style

  <Style x:Key="IconRadioButton" TargetType="cbtn:RadioButton2">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="cbtn:RadioButton2">
                    <Border Background="{TemplateBinding Background}" CornerRadius="10">
                        <StackPanel Orientation="Horizontal">
                            <Path x:Name="icon1" Data="{TemplateBinding Icon}" Width="{TemplateBinding IconWidth}" Height="{TemplateBinding IconHeight}" Fill="{TemplateBinding Foreground}" Stroke="{TemplateBinding Foreground}" StrokeThickness="1" SnapsToDevicePixels="True" Stretch="Uniform"/>
                            <Path x:Name="icon2" Data="{TemplateBinding Icon2}" Width="{TemplateBinding IconWidth}" Height="{TemplateBinding IconHeight}" Fill="{TemplateBinding Foreground}"  Stroke="{TemplateBinding Foreground}" StrokeThickness="1" SnapsToDevicePixels="True" Stretch="Uniform"/>
                            <TextBlock x:Name="tb" Text="{TemplateBinding Name}" Background="{TemplateBinding Background}" Foreground="{TemplateBinding Foreground}" VerticalAlignment="Center"/>
                            <ContentPresenter x:Name="contentPresenter" RecognizesAccessKey="True" VerticalAlignment="Center" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}"/>
                        </StackPanel>
                    </Border>
                    <ControlTemplate.Triggers>
                        <Trigger Property="IsChecked" Value="True">
                            <Setter TargetName="icon1" Property="Visibility" Value="Collapsed"/>
                            <Setter TargetName="icon2" Property="Visibility" Value="Visible"/>
                            <Setter TargetName="tb" Property="Visibility" Value="Collapsed"/>
                            <Setter TargetName="contentPresenter" Property="Visibility" Value="Visible"/>
                        </Trigger>
                        <Trigger Property="IsChecked" Value="False">
                            <Setter TargetName="icon1" Property="Visibility" Value="Visible"/>
                            <Setter TargetName="icon2" Property="Visibility" Value="Collapsed"/>
                            <Setter TargetName="tb" Property="Visibility" Value="Visible"/>
                            <Setter TargetName="contentPresenter" Property="Visibility" Value="Collapsed"/>
                        </Trigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
        <Style.Triggers>
            <Trigger Property="IsChecked" Value="True">
                <Setter Property="Opacity" Value="0.4"/>
            </Trigger>
        </Style.Triggers>
    </Style>

3. Demo

  <cbtn:RadioButton2 Content="rb1選中" x:Name="rb1未選中" Width="80" Height="30" Background="Black" Foreground="White" Style="{StaticResource IconRadioButton}"
                                     Icon="{StaticResource UpGeometry}" Icon2="{StaticResource DownGeometry}" IconWidth="20" IconHeight="20"/>
                    <cbtn:RadioButton2 Content="rb2選中" x:Name="rb2未選中" Width="80" Height="30" Background="Black" Foreground="White" Style="{StaticResource IconRadioButton}"
                                     Icon="{StaticResource UpGeometry}" Icon2="{StaticResource DownGeometry}" IconWidth="20" IconHeight="20"/>
                    <cbtn:RadioButton2 Content="rb3選中" x:Name="rb3未選中" Width="80" Height="30" Background="Black" Foreground="White" Style="{StaticResource IconRadioButton}"
                                     Icon="{StaticResource UpGeometry}" Icon2="{StaticResource DownGeometry}" IconWidth="20" IconHeight="20"/>

4.效果

wpf 單選框,wpf,ui,c#
wpf 單選框,wpf,ui,c#
wpf 單選框,wpf,ui,c#
wpf 單選框,wpf,ui,c#文章來源地址http://www.zghlxwxcb.cn/news/detail-829478.html

到了這里,關(guān)于WPF 控件 (四、單選按鈕)的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!

本文來自互聯(lián)網(wǎng)用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務(wù),不擁有所有權(quán),不承擔(dān)相關(guān)法律責(zé)任。如若轉(zhuǎn)載,請注明出處: 如若內(nèi)容造成侵權(quán)/違法違規(guī)/事實不符,請點擊違法舉報進行投訴反饋,一經(jīng)查實,立即刪除!

領(lǐng)支付寶紅包贊助服務(wù)器費用

相關(guān)文章

  • WPF必須掌握的技能之自定義控件——實戰(zhàn):自制上傳文件顯示進度按鈕

    WPF必須掌握的技能之自定義控件——實戰(zhàn):自制上傳文件顯示進度按鈕

    自定義控件在WPF開發(fā)中是很常見的,有時候某些控件需要契合業(yè)務(wù)或者美化統(tǒng)一樣式,這時候就需要對控件做出一些改造。 目錄 按鈕設(shè)置圓角 按鈕上傳文件相關(guān)定義 測試代碼 話不多說直接看效果 默認(rèn)效果: 上傳效果: 按鈕設(shè)置圓角 因為按鈕本身沒有 CornerRadius 屬性,所以只

    2024年02月08日
    瀏覽(40)
  • WPF 使用MaterialDesign(開源UI控件庫)

    WPF 使用MaterialDesign(開源UI控件庫)

    ??????? ?MaterialDesign for WPF 是針對WPF設(shè)計的 開源UI框架 ,使用該UI框架可以很方便使用各種封裝好的絢麗的控件,方便快速設(shè)計UI界面。 官網(wǎng)鏈接:http://materialdesigninxaml.net/ MaterialDesign Github源碼鏈接:https://github.com/MaterialDesignInXAML/MaterialDesignInXamlToolkit 本篇實例鏈接:htt

    2024年02月14日
    瀏覽(20)
  • Android Studio:單選按鈕和復(fù)選框

    Android Studio:單選按鈕和復(fù)選框

    安卓應(yīng)用中,常常需要用戶從若干選項中進行選擇,有時要求只能選擇一個,那么就要使用單選按鈕(RadioButton),有時要求用戶可以選擇多個,那么就要使用復(fù)選框(CheckBox)。 1、繼承關(guān)系圖 RadioGroup是LinearLayout的子類 2、常用屬性 3、設(shè)置事件監(jiān)聽器 4、注意事項 導(dǎo)入and

    2024年02月06日
    瀏覽(24)
  • c#WPF 自定義UI控件學(xué)習(xí),vb.net界面UI美化

    c#WPF 自定義UI控件學(xué)習(xí),vb.net界面UI美化

    最近項目中運用到了WPF處理三維軟件,在C/S結(jié)構(gòu)中WPF做UI還是有很多優(yōu)越性,簡單的學(xué)了一點WPF知識,成功的完成項目目標(biāo)。項目過度階段對于WPF的一些基本特點有了進一步了解 。至此花費一點時間研究研究WPF控件。 為以后的項目開發(fā)中提供一些可觀的資源也是不錯的。 目

    2024年02月20日
    瀏覽(21)
  • 基于Visual Studio擴展的WPF工業(yè)組態(tài)UI控件-ConPipe

    基于Visual Studio擴展的WPF工業(yè)組態(tài)UI控件-ConPipe

    本文的組態(tài)控件是由《輕量而敏捷的工業(yè)組態(tài)軟件UI設(shè)計工具-ConPipe Studio 2022》 和 《輕量而敏捷的工業(yè)組態(tài)軟件UI設(shè)計工具-機械組態(tài)篇》兩篇文章中的方案全新升級而來的,升級控件依然繼承了“程序員自己能干的事情絕不麻煩美工”的思想。最大的不同就是由ConPipe Studio工

    2023年04月16日
    瀏覽(57)
  • 基于Material Design風(fēng)格開源、易用、強大的WPF UI控件庫

    基于Material Design風(fēng)格開源、易用、強大的WPF UI控件庫

    今天大姚給大家分享一款基于Material Design風(fēng)格開源、免費(MIT License)、易于使用、強大的WPF UI控件庫: MaterialDesignInXamlToolkit 。 MaterialDesignInXamlToolkit 是一個開源、易于使用、強大的 WPF UI 控件庫,旨在幫助開發(fā)人員在 C# 和 VB.Net 中實現(xiàn) Google 的 Material Design 風(fēng)格的用戶界面。

    2024年04月23日
    瀏覽(41)
  • Android 之 RadioButton (單選按鈕)& Checkbox (復(fù)選框)

    Android 之 RadioButton (單選按鈕)& Checkbox (復(fù)選框)

    本節(jié)給大家?guī)淼氖茿ndoird基本UI控件中的RadioButton和Checkbox; 先說下本節(jié)要講解的內(nèi)容是:RadioButton和Checkbox的 1.基本用法 2.事件處理; 3.自定義點擊效果; 4.改變文字與選擇框的相對位置; 5.修改文字與選擇框的距離 其實這兩個控件有很多地方都是類似的,除了單選和多選,

    2024年02月10日
    瀏覽(41)
  • 界面控件DevExpress WPF流程圖組件,完美復(fù)制Visio UI!(一)

    界面控件DevExpress WPF流程圖組件,完美復(fù)制Visio UI!(一)

    DevExpress WPF Diagram(流程圖)控件幫助用戶完美復(fù)制Microsoft Visio UI,并將信息豐富且組織良好的圖表、流程圖和組織圖輕松合并到您的下一個WPF項目中。 P.S :DevExpress WPF擁有120+個控件和庫,將幫助您交付滿足甚至超出企業(yè)需求的高性能業(yè)務(wù)應(yīng)用程序。通過DevExpress WPF能創(chuàng)建有

    2024年02月04日
    瀏覽(29)
  • 界面控件DevExpress WPF流程圖組件,完美復(fù)制Visio UI!(二)

    界面控件DevExpress WPF流程圖組件,完美復(fù)制Visio UI!(二)

    DevExpress WPF Diagram(流程圖)控件幫助用戶完美復(fù)制Microsoft Visio UI,并將信息豐富且組織良好的圖表、流程圖和組織圖輕松合并到您的下一個WPF項目中。 在上文中(點擊這里回顧),我們?yōu)榇蠹医榻B了DevExpress WPF Diagram(流程圖)組件性能優(yōu)異切信息豐富的流程圖功能、輕松地

    2024年02月05日
    瀏覽(31)
  • WPF-UI HandyControl 控件簡單實戰(zhàn)+IconPacks矢量圖導(dǎo)入

    WPF-UI HandyControl 控件簡單實戰(zhàn)+IconPacks矢量圖導(dǎo)入

    因為HandyControl 的功能非常的豐富,我打算完整的了解一下HandyControl 整個控件的基本使用,而且我的網(wǎng)易云WPF項目也打算用UserControl 進行重構(gòu) WPF-UI HandyControl 簡單介紹 HandyControl Visual Studio 插件 HandyControl Github地址 HandyControl 官方中文文檔 HandyControl 實戰(zhàn)Gitee倉庫 我們下載了Han

    2024年02月02日
    瀏覽(118)

覺得文章有用就打賞一下文章作者

支付寶掃一掃打賞

博客贊助

微信掃一掃打賞

請作者喝杯咖啡吧~博客贊助

支付寶掃一掃領(lǐng)取紅包,優(yōu)惠每天領(lǐng)

二維碼1

領(lǐng)取紅包

二維碼2

領(lǐng)紅包