WPF - 这是一堆代码片段的集合

1. Image的Source设定,引用的图片文件在其他的dll中。图片的Build action : Resource

如果是直接写:

Source="/MyProject.Resources;Component/Images/Icon.gif"  

如果是binding

Source="{Binding Path=Path}"

// code behind:
Path = "pack://application:,,,/MyProject.Resources;component/Images/Icon.gif";

 2. C#执行外部Exe

            Process proc = new Process();
            proc.StartInfo = new ProcessStartInfo()
            {
                FileName = @"abc.pdf" //put your path here
            };
            proc.Start();

 3. Listbox 选中item不高亮

<Style.Resources>
    <!-- Background of selected item when focussed -->
    <SolidColorBrush x:Key="{x:Static SystemColors.HighlightBrushKey}"
                     Color="Green"/>
    <!-- Background of selected item when not focussed -->
    <SolidColorBrush x:Key="{x:Static SystemColors.ControlBrushKey}"
                     Color="LightGreen" />
</Style.Resources> 

4. set focus in textbox in WPF

<StackPanel FocusManager.FocusedElement="{Binding ElementName=Box}">
   <TextBox Name="Box" />
</StackPanel>

  

5. 2014-12-09 DataGrid中,默认会选中第一行,如果想取消选中。以后都不选。可以这样:

<DataGrid x:Name="data"  IsSynchronizedWithCurrentItem="{x:Null}" ...>

  

 

posted @ 2014-08-27 14:26  太古月石  阅读(410)  评论(0编辑  收藏  举报