原創(chuàng)|其它|編輯:郝浩|2012-12-20 10:20:50.000|閱讀 409 次
概述:在Mindscape WPF Elements屬性網(wǎng)格中包含了一個(gè)內(nèi)置的編輯器,今天就來(lái)看看如何自定義內(nèi)置編輯器,你可以使用Windows Presentation Foundation定義編輯器樣式。
# 界面/圖表報(bào)表/文檔/IDE等千款熱門軟控件火熱銷售中 >>
相關(guān)鏈接:
在Mindscape WPF Elements屬性網(wǎng)格中包含了一個(gè)內(nèi)置的編輯器,今天就來(lái)看看如何自定義內(nèi)置編輯器。
定義內(nèi)置編輯器
你可以使用Windows Presentation Foundation定義編輯器樣式。
選擇一個(gè)內(nèi)置的編輯器
屬性網(wǎng)格提供的內(nèi)置編輯器的其中一個(gè)是由數(shù)字升降控制的,這個(gè)就比較適合于年齡屬性,為了告知屬性網(wǎng)格使用對(duì)于年齡的編輯器,以通常的方式指定一個(gè)屬性編輯器,但設(shè)置編輯器模版到內(nèi)置的NumericUpDown編輯器關(guān)鍵資源。
示例如下:
<ms:PropertyEditor PropertyName='Age' DeclaringType='{x:Type t:Person}' EditorTemplate='{StaticResource {x:Static ms:PropertyGrid.NumericUpDownEditorKey}}'> <ms:PropertyEditor.Style> <Style TargetType='{x:Type ms:NumericUpDown}'> <Setter Property='Minimum' Value='1'/> <Setter Property='Maximum' Value='150'/> </Style> </ms:PropertyEditor.Style> </ms:PropertyEditor>
樣式化內(nèi)置的編輯器
上面的例子顯示了一個(gè)簡(jiǎn)單的例子,使用屬性編輯器樣式來(lái)配置一個(gè)內(nèi)置編輯器。在接下來(lái)的例子中,我們指定了內(nèi)置選擇框編輯器擁有工作許可證屬性,和替換默認(rèn)的復(fù)選框模板來(lái)實(shí)現(xiàn)與眾不同的視覺(jué)效果:
<ms:PropertyEditor PropertyName='HasWorkPermit' DeclaringType='{x:Type t:Person}' EditorTemplate='{StaticResource {x:Static ms:PropertyGrid.CheckBoxEditorKey}}'> <ms:PropertyEditor.Style> <Style TargetType='{x:Type CheckBox}'> <Setter Property='Template'> <Setter.Value> <ControlTemplate TargetType='{x:Type CheckBox}'> <StackPanel Orientation='Horizontal'> <Border x:Name='YesBorder' CornerRadius='3' BorderThickness='1' Margin='2' IsHitTestVisible='False' Padding='2' BorderBrush='Blue'> <Border.Background> <LinearGradientBrush StartPoint='0,0' EndPoint='0,1'> <GradientStop Offset='0' Color='AliceBlue'/> <GradientStop Offset='1' Color='Aquamarine'/> </LinearGradientBrush> </Border.Background> <TextBlock x:Name='YesText' FontWeight='Bold' Foreground='Black'>YES</TextBlock> </Border> <Border x:Name='NoBorder' CornerRadius='3' BorderThickness='1' Margin='2' Padding='2' BorderBrush='Red'> <Border.Background> <LinearGradientBrush StartPoint='0,0' EndPoint='0,1'> <GradientStop Offset='0' Color='LightPink'/> <GradientStop Offset='1' Color='MediumVioletRed'/> </LinearGradientBrush> </Border.Background> <TextBlock x:Name='NoText' FontWeight='Bold' Foreground='Transparent'>NO</TextBlock> </Border> </StackPanel> <ControlTemplate.Triggers> <Trigger Property='IsChecked' Value='False'> <Setter TargetName='YesText' Property='Foreground' Value='Transparent'/> <Setter TargetName='NoText' Property='Foreground' Value='White'/> <Setter TargetName='YesBorder' Property='IsHitTestVisible' Value='True'/> <Setter TargetName='NoBorder' Property='IsHitTestVisible' Value='False'/> </Trigger> </ControlTemplate.Triggers> </ControlTemplate> </Setter.Value> </Setter> </Style> </ms:PropertyEditor.Style> </ms:PropertyEditor>
本站文章除注明轉(zhuǎn)載外,均為本站原創(chuàng)或翻譯。歡迎任何形式的轉(zhuǎn)載,但請(qǐng)務(wù)必注明出處、不得修改原文相關(guān)鏈接,如果存在內(nèi)容上的異議請(qǐng)郵件反饋至chenjj@fc6vip.cn
文章轉(zhuǎn)載自:慧都控件