1.
Custom Dataform用来新增一条记录。
下面那么多属性就是我们需要填写的所有字段。
public string this[string columnName]
{
get
{
string result = null;
if (columnName == "Name")
{
if (String.IsNullOrEmpty(Name))
result = "Firstname has to be set!";
else if (Name.Length < 3)
}
return result;
我们这里使用Resource Dictionary来存放模板信息:
定义DataForm的模板如下:
<
Setter
Property
="Template">
<
Setter.Value
>
<
Border
Background
="{
TemplateBinding
Background
}"
CornerRadius="3" Width="{TemplateBinding Width}">
<
Grid
>
<
TextBlock
Grid.Column
="0"
Grid.Row
="0"
Text="Address:" Style="{StaticResource tb}" />
Text="{Binding Path=TheRestaurant.Address, Mode=TwoWay, ValidatesOnDataErrors=True}" IsReadOnly="{Binding IsLocked}"/>
<
TextBlock
Grid.Column
="0"
Grid.Row
="1"
Text="Code:" Style="{StaticResource tb}"/>
Text="{Binding Path=TheRestaurant.Code, ValidatesOnDataErrors=True}" IsReadOnly="{Binding IsLocked}"/>
<
TextBlock
Grid.Column
="0"
Grid.Row
="2"
Text="ContactName:" Style="{StaticResource tb}"/>
Text="{Binding Path=TheRestaurant.ContactName, Mode=TwoWay}" IsReadOnly="{Binding IsLocked}" />
<
TextBlock
Grid.Column
="0"
Grid.Row
="3"
Text
="ContactTitle:"
Style="{StaticResource tb}"/>
Text="{Binding Path=TheRestaurant.ContactTitle, TargetNullValue=Doctor}" IsReadOnly="{Binding IsLocked}"/>
<
TextBlock
Grid.Column
="0"
Grid.Row
="4"
Text="Fax:" Style="{StaticResource tb}"/>
Text="{Binding Path=TheRestaurant.Fax, Mode=TwoWay}" IsReadOnly="{Binding IsLocked}"/>
<
TextBlock
Grid.Column
="0"
Grid.Row
="5"
Text="ID:" Style="{StaticResource tb}"/>
Text="{Binding Path=TheRestaurant.ID, Mode=TwoWay}"
AcceptsReturn="True" textwrapping="Wrap" IsReadOnly="{Binding IsLocked}"/>
<
TextBlock
Grid.Column
="0"
Grid.Row
="6"
Text="Name:" Style="{StaticResource tb}"/>
Text="{Binding Path=TheRestaurant.Name, ValidatesOnDataErrors=True}" IsReadOnly="{Binding IsLocked}"/>
<
TextBlock
Grid.Column
="0"
Grid.Row
="7"
Text
="Phone:"
Style="{StaticResource tb}"/>
Text="{Binding Path=TheRestaurant.Phone, ValidatesOnDataErrors=True}" IsReadOnly="{Binding IsLocked}"/>
<
TextBlock
Grid.Column
="0"
Grid.Row
="8"
Text="Region:"
Style="{StaticResource tb}"/>
Text="{Binding Path=TheRestaurant.Region, TargetNullValue=Beijing, ValidatesOnDataErrors=True}" IsReadOnly="{Binding IsLocked}"/>
</
Grid
>
</
Border
>
</
ControlTemplate
>
</
Setter.Value
>
</
Setter
>
</
Style
>
先说如何新增记录吧
需要创建一个子窗体。
Click事件如下:
custDataform.Margin = new Thickness(3);
custDataform.Width = 450;
custDataform.TheRestaurant = new Customrstaurant();
custDataform.IsLocked = false;
cw.LayoutRoot.Children.Add(custDataform);
cw.HasCloseButton = false;
cw.Title = "New Restuarant Detail";
cw.Closed += (s,args) =>
{
if (cw.DialogResult.Value && custDataform.IsValid)
{
}
};
cw.Closing += (s,args) =>
{
if (!custDataform.IsValid && cw.DialogResult.Value)
{
MessageBox.Show("Some of field values are not valid.");
args.Cancel = true;
}
};
cw.Show();
运行一下,
最后一步是如何使用RIA Service更新数据源了。
在Closed事件发生后加入如下代码:
2.
使用SilverlightControlToolkit中的皮肤。
这里需要使用到ICommand方法。
先创建一个Class:
public
class ThemeChangeCommand :ICommand
{
public bool CanExecute(object parameter)
{
return true;
}
public event EventHandler CanExecuteChanged;
public void Execute(object parameter)
{
Theme themeContainer = (Theme)((FrameworkElement)((ContentControl)Application.Current.RootVisual).Content).FindName("ThemeContainer");
string themeName = parameter as string;
if (themeName == null)
{
themeContainer.ThemeUri = null;
}
else
{
themeContainer.ThemeUri =new Uri("/System.Windows.Controls.Theming." + themeName + ";component/Theme.xaml", UriKind.RelativeOrAbsolute);
}
if (CanExecuteChanged != null)
CanExecuteChanged(this, new EventArgs());
}
}
第二步我们需要在APP.xaml中添加如下一句话:
<
helper
:
ThemeChangeCommand
x
:
Key
="themeCommand" />
最后就是修改MainPage.xaml中的Contentborder部分。
运行一下:
右键鼠标就能看到不同的皮肤了。选择个黑色的试试:
前提是你安装了最新的Silverlight Toolkit。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。