以下是 个人参考程序,学习总结的,如果有 甚么不对,请指教,谢谢。

<Page x:Class="BocoOssViewDemo.Demos.Topo.Xaml.StarMoon" <!--后置代码类的名-->
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"<!--这两行默认的,不用管-->
     xmlns:ovt="clr-namespace:BOCO.OssView.Topo;assembly=BOCO.OssView.Topo"<!--为命名空间指定一个别名,如果是本程序集下,不用加后面的assembly-->
     xmlns:local="clr-namespace:BocoOssViewDemo.Demos.Topo.Xaml"<!--本文件的存储位置-->
    Title="星月童话"
    >
  <Page.Resources><!--为本文件(程序)设置资源,contextmenu写在这,可以让整个页面都共享一个contextmenu,及为一个静态的了-->
    <ContextMenu x:Key="nodeContextMenu" StaysOpen="True"><!--x:Key相当于id或者name属性,但是此处需要写成x:Key-->
      <MenuItem Header="{Binding Path=Host}"/><!--为menuItem 绑定数据,如果没有指定Source属性,则数据从控件的DataContext 中查找。path对应表中的列或者是类的属性,如果source和path都不指定,只有binding,及为整个对象,从datacontext中获取。-->
      <Separator/>
      <MenuItem Header="可拖动" IsCheckable="True" IsChecked="{Binding Path=CanDrag}"/>
      <MenuItem Header="选中" IsCheckable="True" IsChecked="{Binding Path=IsSelected}"/>
      <MenuItem Header="显示" IsCheckable="True" IsChecked="{Binding Path=IsVisible}"/>
    </ContextMenu>
 <!--动态设置样式,对于静态的样式,如这个程序的button 等控件的样式,可以参考c:\Program Files\Microsoft SDKs\Windows\v6.0\Samples\WPFSamples\Controls\ControlTemplateExamples\CSharp\Resources文件-->
  <Style TargetType="{x:Type ovt:NodeUI}"><!--为Namespace的别名为ovt的类中的NodeUI设置样式-->
      <Setter Property="ContextMenu" Value="{StaticResource nodeContextMenu}"/><!--为NodeUI设置contextmenu,指定为上面定义的contextmenu,由于该contextmenu是在本文件(程序)的资源里面设置,因此,Value属性中用StaticResource,当然,也还有“动态资源”value的用法: 资源类型+资源名称-->
      <Setter Property="Control.Template"><!--为NodeUI控件设置样式-->
        <Setter.Value>
          <ControlTemplate TargetType="{x:Type ovt:NodeUI}">
            <ContentPresenter Content="{Binding}"      
              ContentTemplateSelector="{x:Static local:NodeTemplateSelector.Instance}"/><!--NodeTemplateSelector.Instance为本程序中的一个静态类的方法-->
          </ControlTemplate>
        </Setter.Value>
      </Setter>

      <Style.Triggers><!--设置事件处理方法或者叫触发器-->
        <Trigger Property="IsMouseOver" Value="True">
          <Setter Property="BitmapEffect"><!--BitmapEffect为一个类,OuterGlowBitmapEffect从它派生-->
            <Setter.Value>
              <OuterGlowBitmapEffect GlowColor="{Binding Path=Severity,Mode=OneWay,Converter={x:Static ovt:SeverityColorConverter.Default}}"<!--Mode枚举类型   BindingMode枚举,值有 TwoWay,OneWay,OneTime,OneWayToSource,  Default 其作用介绍(个人理解):OneWay,程序或者界面属性值的改变不会互相影响--><!--Converter介绍:x:Static 指定是静态类,后面是命名空间下的静态方法-->
                                     GlowSize="5" Noise="0.1" Opacity="0.8"/><!--设置一种加深的效果,如线条加粗,颜色变亮等。-->
            </Setter.Value>
          </Setter>
        </Trigger>
        <DataTrigger Binding="{Binding Path=IsSelected}" Value="True"><!--数据改变的触发-->
          <Setter Property="BitmapEffect">
            <Setter.Value>
              <OuterGlowBitmapEffect GlowColor="{Binding Path=Severity,Mode=OneWay,Converter={x:Static ovt:SeverityColorConverter.Default}}"
                                     GlowSize="5" Noise="0.1" Opacity="0.8"/>
            </Setter.Value>
          </Setter>
        </DataTrigger>
      </Style.Triggers>
    </Style>
    <ovt:LinePathCreator x:Key="linePathCreator"/><!--把对象加载到本页面,并指定名字-->
    <ovt:PolylinePathCreator x:Key="polylinePathCreator"/>
    <ovt:ArcPathCreator x:Key="arcPathCreator"/>
    <ContextMenu x:Key="linkContextMenu" StaysOpen="True" Opened="linkContextMenu_Opened">
      <MenuItem Header="请选择Link的布线方式:" />
      <Separator/>
      <RadioButton Name="miLine" Content="直线" IsChecked="True"
                   Tag="{StaticResource linePathCreator}" Checked="radioButton_Checked"/>
<!-- Tag="{StaticResource linePathCreator}" StaticResource 及为本页面资源,linePathCreator及为前面所加载的对象-->
      <RadioButton Name="miPolyline" Content="折线" IsChecked="False"
                   Tag="{StaticResource polylinePathCreator}" Checked="radioButton_Checked"/>
      <RadioButton Name="miArc" Content="曲线" IsChecked="False"
                   Tag="{StaticResource arcPathCreator}" Checked="radioButton_Checked"/>
    </ContextMenu>
    <Style TargetType="{x:Type ovt:LinkUI}">
      <Setter Property="ContextMenu" Value="{StaticResource linkContextMenu}"/><!--为LinkUI控件指定本页面定义的ContextMenu-->
      <Setter Property="PathCreator" Value="{StaticResource linePathCreator}"/>
    </Style>
  </Page.Resources>
  <Grid Background="White" VerticalAlignment="Stretch" HorizontalAlignment="Stretch" >
    <Grid.RowDefinitions>
      <RowDefinition  Height="28"></RowDefinition>
      <RowDefinition  Height="*"></RowDefinition>
    </Grid.RowDefinitions>
    <ToolBarTray  AllowDrop="True" Grid.Row="0" Grid.Column="0" >
      <ToolBar>
        <Button Width="20" Height="20" Background="Transparent">
          <Image Source="..\..\..\Images\toolbar\select.png" />
        </Button>
        <Button Width="20" Height="20" Background="Transparent">
          <Image Source="..\..\..\Images\toolbar\zoomIn.png" />
        </Button>
        <Button Width="20" Height="20" Background="Transparent">
          <Image Source="..\..\..\Images\toolbar\zoomOut.png" />
        </Button>

      </ToolBar>
    </ToolBarTray>
    <ovt:NetworkPanel Name="myNetwork" Grid.Row="1" Grid.Column="0" />
   
  </Grid>
</Page>

 

posted on 2007-12-14 16:50  颜昌钢  阅读(1206)  评论(1编辑  收藏  举报