listbox中添加图片的方法
Image cctvima = new Image();
cctvima.Source = new BitmapImage(new Uri("http://www.365css.cn/upload/sanguoweishi.jpg"));
listBox1.Items.Add(cctvima);
Storyboard s = (Storyboard)Resources["Story"];
其中“story”为storyboard的key
注意添加头文件using System.Windows.Media.Animation;
属性触发器(Property Trigger)
<Button MinWidth=”75” Margin=”10”>
<Button.Style>
<Style TargetType=”{x:Type Button}”>
<Style.Triggers>
<Trigger Property=”IsMouseOver” Value=”True”>
<Setter Property=”Foreground” Value=”Blue”/>
</Trigger>
</Style.Triggers>
</Style>
</Button.Style>
OK
</Button>
要想实现菜单栏随着主框架的伸缩而保持长度伸缩,高度不变,方法如下:
固定grid的第一行的高度,将menu至于第一行中。同时用菜单栏将现在的第一行填充,设置HorizontalAlignment="Stretch"即可实现。
渐变色彩的XAML设置
<MenuItem.Background>
<LinearGradientBrush StartPoint="0,0.5" EndPoint="0.5,1">
<GradientStop Color="Green" Offset="0.0"/>
<GradientStop Color="White" Offset="0.9"/>
</LinearGradientBrush>
</MenuItem.Background>
定时器的使用
添加命名空间,using System.Windows.Threading;
public MainWindow()//初始化
{
this.InitializeComponent();
DispatcherTimer dt = new DispatcherTimer();
dt.Interval = TimeSpan.FromSeconds(1);
dt.Tick += new EventHandler(dt_Tick);//调用函数
dt.Start();
}
void dt_Tick(object sender, EventArgs e)
{
this.LabelShowTime.Content = DateTime.Now.ToString();
}
窗口动画启动和退出
在<Window.Resources>和</Window.Resources>之间添加动画效果
<Storyboard x:Key="indraw">
<DoubleAnimation Storyboard.TargetName="win" Storyboard.TargetProperty="Opacity" From="0" To="1" Duration="0:0:2"/>
</Storyboard>
然后在cs文件中启动动画即可
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
XML存取数据
XmlDocument xmldoc = new XmlDocument();
XmlNode xmlnode=xmldoc.CreateNode(XmlNodeType.XmlDeclaration, "", "");
xmldoc.AppendChild(xmlnode);
XmlElement root = xmldoc.CreateElement("playlist");
xmldoc.AppendChild(root);
for(int k=0;k<listbox1.Items.Count;k++)
{
XmlElement xe0=xmldoc.CreateElement("song");
xe0.SetAttribute("index",k.ToString());
root.AppendChild(xe0);
XmlElement xe0sub=xmldoc.CreateElement("name");
xe0sub.InnerText=listbox1.Items[k].ToString();
xe0.AppendChild(xe0sub);
}
xmldoc.Save(@"D:\Backup\playlist.xml");
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
XML读取数据
XmlDocument xmldoc=new XmlDocument();
xmldoc.Load(@"D:\Backup\playlist.xml");
XmlNodeReader xmlr=new XmlNodeReader(xmldoc);
string str="";
while(xmlr.Read())
{
switch(xmlr.NodeType)
{
case XmlNodeType.Element:
str=xmlr.Name;
break;
case XmlNodeType.Text:
if(str=="name")
listbox1.Items.Add(xmlr.Value);
break;
}
}