(1)C#中string[]数组和list<string>泛型的相互转换
从string[]转list<string>
string[] str = {"1","2"};
list<string> list =newlist<string>(str);
从list<string>转string[]
list<string> list=newlist<string>;
string[] str=list.toarray();
解决方法:
图片的生成操作改为内容。
(3)通过资源类来绑定资源, 步骤:
a.在程序 App.xml中添加通用类或属性xml:Generic.xaml
<!--Application Resources-->
<
Application.Resources
>
<
ResourceDictionary
>
<
ResourceDictionary.MergedDictionaries
>
<
ResourceDictionary
Source
="Generic.xaml"/>
<
ResourceDictionary
Source
="Themes/Res.xaml"/>
</
ResourceDictionary.MergedDictionaries
>
</
ResourceDictionary
>
</
Application.Resources
>
b. 创建generic.xaml,在其中添加关键属性,该属性对应为程序中的一个类(对象),如下面的LocalizedStrings:
<?xml version="1.0" ?>
<ResourceDictionary
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:zds="clr-namespace:Calendar.Resources">
<zds:LocalizedStringsx:Key="LocalizedStrings"/>
</ResourceDictionary>
c.创建字典对应的类
LocalizedStrings,
其中Appress是资源类
:
using
System;
using
System.Net;
using
System.Windows;
using
System.Windows.Controls;
using
System.Windows.Documents;
using
System.Windows.Ink;
using
System.Windows.Input;
using
System.Windows.Media;
using
System.Windows.Media.Animation;
using
System.Windows.Shapes;
namespace
Calendar.Resources
{
public
class
LocalizedStrings
{
public
LocalizedStrings() { }
private
static
AppRes
localizedResources =
new
AppRes
();
public
AppRes
LocalizedResources
{
get
{
return
localizedResources;
}
}
}
}
d.实现控件的属性绑定 (path,source)
<zdc:ToolsTemplateTilex:Name="test"Grid.Column="0"Grid.Row="0"
TemplateTitle="{BindingPath=LocalizedResources.MenstrualCyclesTitle,Source={StaticResourceLocalizedStrings}}"
Click="OnTempalteTileClick" />
<!--Application Resources-->
<
Application.Resources
>
<
ResourceDictionary
>
<
ResourceDictionary.MergedDictionaries
>
<
ResourceDictionary
Source
="/ZDWorksCommon;component/Themes/Generic.xaml"/>
<
ResourceDictionary
Source
="Generic.xaml"/>
<
ResourceDictionary
Source
="Themes/Res.xaml"/>
</
ResourceDictionary.MergedDictionaries
>
</
ResourceDictionary
>
</
Application.Resources
>
如果加载的路径不正确,vs则会提示
(5)关于计算日期的天数间隔
一种方法是把日期后面的时分秒置为零:
a.DateTimet1 =newDateTime(curDate.Year, curDate.Month, curDate.Day);
DateTime
t2 =
new
DateTime
(cmpDate.Year, cmpDate.Month, cmpDate.Day);
int
daysInterval = (t2-t1).Days;
b.
curDate -= curDate.TimeOfDay;
cmpDate -= cmpDate.TimeOfDay;
int
daysInterval = (
curDate
-
cmpDate
).Days;
(6)关于控件样式的等价问题
<
Style
x
:
Name
="ToolsRootGridStyle"
TargetType
="Grid">
<
Setter
Property
="Grid.Background">
<
Setter.Value
>
<
ImageBrush
ImageSource
="/Images/Common/background.jpg"
Stretch
="None"/>
</
Setter.Value
>
</
Setter
>
</
Style
>
<
Grid
x
:
Name
="LayoutRoot"
Style
="{
StaticResource
ToolsRootGridStyle
}"/>
等价于:
<
Grid
x
:
Name
="LayoutRoot">
<Grid.Backgroud>
<ImageBrushImageSource="/Images/Common/background.jpg"Stretch="None"/>
</Grid.Backgroud>
</Grid>
(7)自定义Eventhandler的参数
a.定义参数类
usingSystem;
using
System.Net;
using
System.Windows;
using
System.Windows.Controls;
using
System.Windows.Documents;
using
System.Windows.Ink;
using
System.Windows.Input;
using
System.Windows.Media;
using
System.Windows.Media.Animation;
using
System.Windows.Shapes;
namespace
Calendar.Controls
{
public
class
AlmanacSelectionChangedEventArgs
:
EventArgs
{
private
AlmanacSelectionChangedEventArgs() { }
internal
AlmanacSelectionChangedEventArgs(
AlmanacInfo
selectedAlmanac)
{
SelectedAlmanac = selectedAlmanac;
}
public
AlmanacInfo
SelectedAlmanac {
get
;
private
set
; }
}
}
b.定义委托事件, 装载参数:
public
event
EventHandler
<
AlmanacSelectionChangedEventArgs
> SelectionChanged;
privatevoidOnDoneButtonClick(objectsender,EventArgsargs)
{
SelectionChanged(sender,newAlmanacSelectionChangedEventArgs(m_SelectedItem));
}
c.注册事件响应,获取参数:
AlmanacPickerPagealmanacPage = e.ContentasAlmanacPickerPage;
if(null!= almanacPage)
{
almanacPage.SelectionChanged += OnSelectionChanged;
}
privatevoidOnSelectionChanged(objectsender,AlmanacSelectionChangedEventArgse)
{
m_AlmanacSelected = e.SelectedAlmanac;
}
(8) 关于ListPicker样式与数据绑定
首先是声明绑定数据源:
<Stylex:Key="AlmanacLPStyle"TargetType="tk:ListPicker">
<
Setter
Property
="FullModeItemTemplate">
<
Setter.Value
>
<
DataTemplate
>
<
StackPanel
Orientation
="Horizontal"
Width
="480"
Height
="80"
Background
="Blue">
<
TextBlock
x
:
Name
="YiBlock"
Text
="{
Binding
YiName
}"
Foreground
="Green"
VerticalAlignment
="Center"/>
<
TextBlock
x
:
Name
="JiBlock"
Text
="{
Binding
JiName
}"
Foreground
="Brown"
VerticalAlignment
="Center" />
</
StackPanel
>
</
DataTemplate
>
</
Setter.Value
>
</
Setter
>
</
Style
>
接着需要做的是定义一个类:
然后定义一个数据源:
publicclasss A
{
publicstringYiName {get;set;}
publicstringJiName{get;set;}
}
然后定义一个数据源:
List<A> list =newList<A>();
list.Add(newA() { YiName ="11", JiName="22"});
list.Add(newA() { YiName ="12", JiName="42"});
YiOrJiSelectLP.ItemSource = list;
1万+

被折叠的 条评论
为什么被折叠?



