LabeledTextBoxControl:

C#定义

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls; namespace Halliburton.Castor.Controls
{
class LabeledTextBoxControl : Control
{
public static readonly DependencyProperty LabelProperty;
public static readonly DependencyProperty TextProperty;
public static readonly DependencyProperty MaxLengthProperty; static LabeledTextBoxControl()
{ Type ownerType = typeof(LabeledTextBoxControl); //FrameworkPropertyMetadata defaultStyleKeyMetadata = new FrameworkPropertyMetadata();
//defaultStyleKeyMetadata.DefaultValue = ownerType;
//DefaultStyleKeyProperty.OverrideMetadata(ownerType, defaultStyleKeyMetadata); FrameworkPropertyMetadata labelMetadata = new FrameworkPropertyMetadata(default(String), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault);
LabelProperty = DependencyProperty.Register("Label", typeof(string), ownerType, labelMetadata); FrameworkPropertyMetadata textMetadata = new FrameworkPropertyMetadata(default(String), FrameworkPropertyMetadataOptions.BindsTwoWayByDefault); TextProperty = DependencyProperty.Register("Text", typeof(string), ownerType, textMetadata); FrameworkPropertyMetadata maxLengthMetadata = new FrameworkPropertyMetadata();
MaxLengthProperty = DependencyProperty.Register("MaxLength", typeof(int), ownerType, maxLengthMetadata);
} public string Label
{
get
{
return (string)GetValue(LabelProperty);
} set
{
SetValue(LabelProperty, value);
}
} public string Text
{
get
{
return (string)GetValue(TextProperty);
} set
{
SetValue(TextProperty, value);
}
} public int MaxLength
{
get
{
return (int)GetValue(MaxLengthProperty);
} set
{
SetValue(MaxLengthProperty, value);
}
}
}
}
Template定义:

<Style x:Key="LabeledTextBoxControl_Style" TargetType="{x:Type controls:LabeledTextBoxControl}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type controls:LabeledTextBoxControl}">
<Grid MaxHeight="30" VerticalAlignment="Center">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock x:Name="Label"
Grid.Column="0"
VerticalAlignment="Center"
FontSize="9pt"
FontWeight="Normal"
Foreground="#FF221F1F"
Style="{StaticResource Univers57_Condensed}"
Text="{TemplateBinding Label}"
TextAlignment="Right" />
<TextBox x:Name="Content"
Grid.Column="1"
Width="Auto"
Height="22"
Margin="4,0,30,0"
VerticalAlignment="Center"
Style="{StaticResource ExpandableTextBox_Style}"
Text="{Binding Text,
UpdateSourceTrigger=PropertyChanged,
RelativeSource={RelativeSource TemplatedParent}}" />
</Grid> </ControlTemplate>
</Setter.Value>
</Setter>
</Style>
使用过程

<controls:LabeledTextBoxControl Grid.Row="0"
Grid.Column="0"
KeyboardNavigation.TabIndex="0"
Label="Project :"
MaxLength="30"
Style="{StaticResource LabeledTextBoxControl_Style}"
Text="{Binding Path=ProjectName,
UpdateSourceTrigger=PropertyChanged}" />

下面是一个用作LabeledCommentControl的例子,其实还是使用的LabeledTextBoxControl,区别是个头大点,可以wrap里面的text

<Style x:Key="LabeledCommentControl_Style" TargetType="{x:Type controls:LabeledTextBoxControl}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type controls:LabeledTextBoxControl}">
<Grid VerticalAlignment="Stretch">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock x:Name="Label"
Grid.Column="0"
Margin="0"
VerticalAlignment="Top"
FontSize="9pt"
FontWeight="Normal"
Foreground="#FF221F1F"
Style="{StaticResource Univers57_Condensed}"
Text="{TemplateBinding Label}"
TextAlignment="Right" />
<TextBox x:Name="Content"
Grid.Column="1"
Width="Auto"
Height="Auto"
Margin="4,0,30,0"
AcceptsReturn="True"
Style="{StaticResource ExpandableTextBox_Style}"
Text="{Binding Text,
UpdateSourceTrigger=PropertyChanged,
RelativeSource={RelativeSource TemplatedParent}}"
TextWrapping="Wrap" />
</Grid> </ControlTemplate>
</Setter.Value>
</Setter>
</Style>

LabeledDatePickerControl:

<controls:LabeledDatePickerControl Grid.Row="2"
Grid.Column="1"
KeyboardNavigation.TabIndex="7"
Label="Date :"
Style="{StaticResource LabeledDatePicker_Style}" />
<Style x:Key="LabeledDatePicker_Style" TargetType="{x:Type controls:LabeledDatePickerControl}">
<Setter Property="Template">
<Setter.Value>
<ControlTemplate TargetType="{x:Type controls:LabeledDatePickerControl}">
<Grid MaxHeight="30" VerticalAlignment="Center">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock x:Name="Label"
Grid.Column="0"
VerticalAlignment="Center"
FontSize="9pt"
FontWeight="Normal"
Foreground="#FF221F1F"
Style="{StaticResource Univers57_Condensed}"
Text="{TemplateBinding Label}"
TextAlignment="Right" />
<DatePicker Grid.Column="1"
Margin="4,0,30,0"
VerticalAlignment="Center"
SelectedDateFormat="Long"
Style="{StaticResource Base_DatePicker_Style}"
Text="{Binding Path=ProjectDate,
Mode=TwoWay,
UpdateSourceTrigger=PropertyChanged}" />
</Grid> </ControlTemplate>
</Setter.Value>
</Setter>
</Style>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls; namespace Halliburton.Castor.Controls
{
class LabeledDatePickerControl : ContentControl
{
public static readonly DependencyProperty LabelProperty; static LabeledDatePickerControl()
{
LabelProperty = DependencyProperty.Register("Label", typeof(string),
typeof(LabeledDatePickerControl),
new FrameworkPropertyMetadata(string.Empty));
}
public string Label
{
get { return (string)GetValue(LabelProperty); }
set { SetValue(LabelProperty, value); }
}
}
}

LabeldControl:

可以装任何controls在label的后面,包括joey的valueEditor,valuedComboBox等

下面是FluidViscosity的例子:

这里例子里的FluidViscosity是用我自己写的LabeledControl 做的,而CasedHoleID是直接用Joey的LabeledMeasurementEditor做的,他里面也有Field的属性和我的label的意思一样。注意可以把任何一个ControlTemplate类型放在一个ContentControl的Template属性下。

这个是CasedHoleID的例子

    <ControlTemplate x:Key="HoleID_Template">
<controls:LabeledMeasurementEditor x:Name="HoleID"
MinWidth="120"
DisplayPrecision="3"
Field="HoleID"
StorageMaximumValue="50"
StorageMinimumValue="0.001"
StorageValue="{Binding HoleID,
UpdateSourceTrigger=PropertyChanged}" />
<ControlTemplate.Triggers>
<DataTrigger Binding="{Binding IsOpenHole}" Value="True">
<Setter TargetName="HoleID" Property="Label" Value="Open Hole ID : " />
</DataTrigger> <DataTrigger Binding="{Binding IsOpenHole}" Value="False">
<Setter TargetName="HoleID" Property="Label" Value="Cased Hole ID : " />
</DataTrigger>
</ControlTemplate.Triggers>
</ControlTemplate>
<ContentControl Grid.Row="2"
Grid.Column="0"
Grid.ColumnSpan="2"
MinWidth="120"
Focusable="False"
Template="{StaticResource HoleID_Template}" />

下面的是FluidViscosity的部分

<controls:LabeledControl Grid.Row="1"
Grid.Column="0"
Grid.ColumnSpan="2"
MinWidth="120"
Margin="20,0,-30,0"
VerticalAlignment="Bottom"
Label="Fluid Viscosity "
Style="{StaticResource HorizontalLabeledControl_Style}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="25" />
</Grid.ColumnDefinitions>
<UnitLibrary_Controls:ValueEditor VerticalAlignment="Bottom"
DisplayPrecision="3"
StorageMaximumValue="10000"
StorageMinimumValue="0.001"
StorageValue="{Binding FluidViscosity,
TargetNullValue=0,
UpdateSourceTrigger=PropertyChanged}"
Style="{StaticResource ValueEditor_Style}" />
<TextBlock Grid.Column="1"
Margin="2,0,0,0"
HorizontalAlignment="Left"
VerticalAlignment="Bottom"
FontSize="9pt"
Foreground="#FF221F1F"
Style="{StaticResource Univers57_Condensed}"
Text="cp" /> </Grid>
</controls:LabeledControl>
<Style x:Key="HorizontalLabeledControl_Style" TargetType="{x:Type controls:LabeledControl}">
<Setter Property="Template" Value="{StaticResource HorizontalLabeledControl_Template}" />
<Setter Property="LabelStyle" Value="{StaticResource Univers57_Condensed}" />
</Style>
<ControlTemplate x:Key="HorizontalLabeledControl_Template" TargetType="{x:Type controls:LabeledControl}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<TextBlock Grid.Column="0"
VerticalAlignment="Center"
FontSize="9pt"
FontWeight="Normal"
Foreground="#FF221F1F"
Style="{TemplateBinding LabelStyle}"
Text="{Binding Label,
RelativeSource={RelativeSource TemplatedParent},
StringFormat=\{0\}:}"
TextAlignment="Right" />
<ContentPresenter Grid.Column="1"
Margin="4,0,30,0"
VerticalAlignment="Center" />
</Grid>
</ControlTemplate>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls; namespace Halliburton.Castor.Controls
{ class LabeledControl:ContentControl
{
public static readonly DependencyProperty LabelProperty;
public static readonly DependencyProperty LabelStyleProperty;
static LabeledControl()
{
Type ownerType = typeof(LabeledControl); LabelProperty = DependencyProperty.Register("Label", typeof(string), ownerType);
LabelStyleProperty = DependencyProperty.Register("LabelStyle", typeof(Style), ownerType); FocusableProperty.OverrideMetadata(ownerType, new FrameworkPropertyMetadata(false));
}
public string Label
{
get { return (string)GetValue(LabelProperty); }
set { SetValue(LabelProperty, value); }
}
public Style LabelStyle
{
get { return (Style)GetValue(LabelStyleProperty); }
set { SetValue(LabelStyleProperty, value); }
}
}
}

另外一个带两个RaidoButton的例子:

<controls:LabeledControl Grid.Row="3"
Grid.Column="6"
Grid.ColumnSpan="3"
Margin="40,0,-30,0"
Label="End Rings "
Style="{StaticResource HorizontalLabeledControl_Style}"
Visibility="{Binding ElementName=BondedToPipe,
Path=IsChecked,
Converter={StaticResource boolToVisibilityConverter}}">
<StackPanel HorizontalAlignment="Left"
VerticalAlignment="Center"
Orientation="Horizontal"
Visibility="{Binding ElementName=BondedToPipe,
Path=IsChecked,
Converter={StaticResource boolToVisibilityConverter}}">
<RadioButton Margin="3,0,0,0"
Content="Standard"
IsChecked="{Binding ToolInfo.IsStandard}"
Style="{StaticResource RadioButton_Style}" />
<RadioButton Margin="10,0,0,0"
Content="K2 End-Ring"
IsChecked="{Binding ToolInfo.IsK2}"
Style="{StaticResource RadioButton_Style}" />
</StackPanel>
</controls:LabeledControl>

Labeled ContentControl & LabeledControl【项目】的更多相关文章

  1. SILVERLIGHT 应急卫生模拟演练项目之childwindow

    项目中经常要用到childwindow 默认SL提供的界面很不好看 也很难适应系统里的要求 单调的界面 木关系 可以我们可以通过BLEND自定义成我们想要的 首先新建立一个SILVERLIGHT 子窗 ...

  2. ContentControl 与 ViewModel (一)

    前阵子有人问我MVVM模式下,在View中嵌套View,切换View.想一想还是写下来吧. 主要就是用到 ContentControl 和 DataTemplate,这算是一种 ViewModel F ...

  3. WPF入门教程系列(一) 创建你的第一个WPF项目

    WPF入门教程系列(一) 创建你的第一个WPF项目 WPF基础知识 快速学习绝不是从零学起的,良好的基础是快速入手的关键,下面先为大家摞列以下自己总结的学习WPF的几点基础知识: 1) C#基础语法知 ...

  4. 如何参与一个GitHub开源项目

    Github作为开源项目的著名托管地,可谓无人不知,越来越多的个人和公司纷纷加入到Github的大家族里来,为开源尽一份绵薄之力.对于个人来讲,你把自己的项目托管到Github上并不表示你参与了Git ...

  5. DeepLearning.ai学习笔记(三)结构化机器学习项目--week2机器学习策略(2)

    一.进行误差分析 很多时候我们发现训练出来的模型有误差后,就会一股脑的想着法子去减少误差.想法固然好,但是有点headlong~ 这节视频中吴大大介绍了一个比较科学的方法,具体的看下面的例子 还是以猫 ...

  6. 【分享】2017 开源中国新增开源项目排行榜 TOP 100

    2017 年开源中国社区新增开源项目排行榜 TOP 100 新鲜出炉! 这份榜单根据 2017 年开源中国社区新收录的开源项目的关注度和活跃度整理而来,这份最受关注的 100 款开源项目榜单在一定程度 ...

  7. WPF项目学习.三

    工具代码记录 版权声明:本文为博主初学经验,未经博主允许不得转载. 一.前言 记录在学习与制作WPF过程中遇到的解决方案. 分页控件的制作,邮件发送,日志代码,excel导入导出等代码的实现过程: 二 ...

  8. GitHub上个最有意思的项目合集(技术清单系列)

    没有1K以上的星星都不好意思推荐给大家!林子大了,啥项目都有,这里给大家搜罗了10个Github上有趣的项目.如果你就着辣椒食用本文,一定会激动的流下泪来...... 1.一行代码没有 | 18k s ...

  9. ContentControl as CC和ContentPresenter as CP的使用

    1.CC为文本控件的父类,它继承为control,所以他是控件, 2.CP继承FrameworkElement,所以他是容器,相当于占位符 3.想让控件中能包含子控件就需要用CP,反之用CC就行.(不 ...

随机推荐

  1. 【Java】SHA加密

    package sdfg; import java.math.BigInteger; import java.security.MessageDigest; import java.security. ...

  2. noSession or session is close 错误

    <filter> <filter-name>OpenSessionInViewFilter</filter-name> <filter-class>or ...

  3. ecshop 改变sitemap.xml的位置

    大家知道ECSHOP默认的sitemap.xml文件是放置在data文件夹中的,但是这不利于GOOGLE的抓取.我们必须把sitemap.xml文件放置在根目录下 在admin/sitemap.php ...

  4. 【Django】Python虚拟环境工具virtualenv

    教程 第一步:安装virtualenv $pip install virtualenv 第二步:开启虚拟环境的python $cd ENV/Scripts $activate.bat #启用virtu ...

  5. 大数据分析的众包平台—Kaggle

    众包(Jeff Howe,2006)是一种在互联网蓬勃发展的背景下产生的一种创新的生产组织形式.在这样的商业模式下,企业利用网络将工作分配出去,通过让更合适的人群参与其中来发现创意和解决技术问题.比较 ...

  6. suse10的网络配置(静态IP)

    感觉跟fedora的差别还是蛮大的, 主要是配置文件的不同, 尤其是默认路由, 多了一个单独的文件ifroute-xxx    suse10的网卡配置文件在/etc/sysconfig/network ...

  7. JSTL(fn函数)

    JSTL(fn函数) 首先,我们要在页面的最上方引用: <%@ taglib prefix="fn" uri="http://java.sun.com/jsp/js ...

  8. 字符串中符号的替换---replace的用法

    #include<iostream> #include<string> using namespace std; int main() { string s1 = " ...

  9. Loadrunner常用的分析要点都有哪些

    提供了生产负载的虚拟用户运行状态的相关信息,可以帮助我们了解负载生成的结果. Rendezvous(负载过程中集合点下的虚拟用户): 当设置集合点后会生成相关数据,反映了随着时间的推移各个时间点上并发 ...

  10. Windows平台分布式架构-负载均衡(高并发)

    缘由 单纯想在winodows平台部署分布式程序,微软在IIS扩展的介绍中有涉及到Application Request Router + Web Farm + Url Rewriter可以实现分布式 ...