WPF ContextMenu ControlTemplate Example

Windows Presentation Foundation (WPF) controls in a visual tree that contains the control's ControlTemplate . Can be a control by modifying the ControlTemplate to change the control structure and appearance. Can not just replace the control part of the visual tree; to change the visual tree control must be the control of the Template property to the new complete ControlTemplate .

Setting example:

<Style TargetType="{x:Type ContextMenu}">
  <Setter Property="SnapsToDevicePixels" Value="True"/>
  <Setter Property="OverridesDefaultStyle" Value="True"/>
  <Setter Property="Grid.IsSharedSizeScope" Value="true"/>
  <Setter Property="HasDropShadow" Value="True"/>
  <Setter Property="Template">
      <ControlTemplate TargetType="{x:Type ContextMenu}">
          Background="{StaticResource WindowBackgroundBrush}"
          BorderBrush="{StaticResource SolidBorderBrush}"
          BorderThickness="1" >
          <StackPanel IsItemsHost="True" KeyboardNavigation.DirectionalNavigation="Cycle"/>
          <Trigger Property="HasDropShadow" Value="true">
            <Setter TargetName="Border" Property="Padding" Value="0,3,0,3"/>
            <Setter TargetName="Border" Property="CornerRadius" Value="4"/>

The above example uses the following resources:

<SolidColorBrush x:Key="WindowBackgroundBrush" Color="#FFF" />


<SolidColorBrush x:Key="SolidBorderBrush" Color="#888" />

the complete example, see an example of using ControlTemplates set the style .



Can control the style of the design criteria

Other resources

ControlTemplate Examples

From: http://msdn.microsoft.com/zh-cn/library/ms744758 (VS.90). aspx

分类:DotNet 时间:2010-05-13 人气:280
blog comments powered by Disqus


  • [Tomcat Source Series] Structure of 2) Life of control structure 2010-03-28

    A life based on the control structure Tomcat lifetime control is a two-tier structure 1) Lifecycle (org.apache.catalina.Lifecycle): The first one to see the various components (Service, Connector, Engine, Host, Context, Wrapper) will implement this i

  • [Tomcat Source Series] Structure of 3) request processing control structure 2010-03-28

    First, the basis of the request processing control structure and life of structures similar to the request processing is a two-tier structure 1.Valve: Valve is the smallest processing unit, we look at the definition of Valve A Valve is a request proc

  • Disczu! 6.0, jsprun database structure & Discuz! 6.1.0 the meaning of the control structure of the table 2010-03-23

    Disczu! 6.0 database structure & Discuz! 6.1.0 the meaning of the data table structure control cdb_access user rights table cdb_adminactions management action table cdb_admingroups Management Unit Data Sheet cdb_adminnotes administrator Message cdb_a

  • PL / SQL (oracle) 2_ control structure 2011-07-04

    A control structure, branch structure 1, if Note: elsif and else If if( Conditions )then ... ... elsif ... ... end if ; 2, case Note: select case statement can omit the condition, when followed either a specific value, can also be one or more conditi

  • Oracle Study Notes (3) PLSQL program control structure 2010-03-20

    This is the third chapter of the study notes, study completed after the second chapter of the programming basics, from now to learn Oracle programming the ... ..., I hope that we can give some support ah! This is after all not to work overtime on Sat

  • Oracle PLSQL Study Notes (blocks. Control structure. Process. Function. Package) 2010-07-21

    Oracle PL / SQL study notes 1, PL / SQL block Block defines the syntax: DECLARE / * Definition section - define constants, variables, complex data types, the cursor * / BEGIN / * Operative --PL/SQL statements and SQL statements * / EXCEPTION / * Some

  • Oracle PLSQL program control structure 2010-11-11

    Sql Code declare n_empno employee.empno% type; v_name employee. name% type; n_salary employee.salary% type; v_temp varchar2 (30); n_temp number (5): = 1; - Custom exception e_exception exception; declare n_empno employee.empno%type; v_name employee.n

  • jquery iframe control static pages a property .. 2010-06-13

    Following the last word to html using jcob after resolution, there can not set the page size of the problem, and finally fixed the page with the iframe display size, taking into account security issues, iframe's src value of the dynamic page loads. .

  • Android ListView control to solve the rolling black background 2011-01-10

    If we use the non-black background when the ListView control, Android ListView by default may scroll the list control's background when suddenly become black. This may cause the program to the black background and not the subject of the main program

  • anroid the RelativeLayout some xml configuration 2010-12-05

    android:id Appropriate for the control ID android:text Among the specified control the text displayed, should be noted that , Here make use of string.xml android:gravity The basic position of the specified control, such as the center , Ranking positi

iOS 开发

Android 开发

Python 开发



PHP 开发

Ruby 开发






Javascript 开发

.NET 开发



Copyright (C) codeweblog.com, All Rights Reserved.

CodeWeblog.com 版权所有 闽ICP备15018612号

processed in 0.120 (s). 12 q(s)