Nothing is everything.
Thursday, January 7, 2010
Drag and Drop in WPF
http://www.codeproject.com/Articles/42696/Textbox-Drag-Drop-in-WPF.aspx
Saturday, January 2, 2010
Accessing Resources in Other Assemblies
<SolidColorBrush
x:Key="{ComponentResourceKey TypeInTargetAssembly={x:Type local:MyClass},
ResourceId=MyClassBrush}">Yellow</SolidColorBrush>
<Button Background="{DynamicResource {x:Static otherAssembly:MyClass.MyClassBrushKey}}"/>
WPF unleashed, page 256
Merging Resources
<Window.Resources>
<ResourceDictionary>
<ResourceDictionary.MergedDictionaries>
<ResourceDictionary Source=”±file1.xaml”±/>
<ResourceDictionary Source=”±file2.xaml”±/>
</ResourceDictionary.MergedDictionaries>
</ResourceDictionary>
</Window.Resources>
WPF unleashed, page 253.
Accessing Resources Embedded in Another Assembly
AssemblyReference;Component/ResourceName
WPF unleashed, page243
A complete table about resources accessing methods, page 242.
How do I create a full-trust XAML Browser Application?
If you want to take advantage of functionality that requires a higher level of trust yet still want
to be integrated into a browser,you can indeed configure an XBAP to require full trust. The
two actions to enable this are a bit convoluted,however:
1. In the ClickOnce application manifest (app.manifest),add Unrestricted=”true” to
the PermissionSet XML element. For example:
<PermissionSet class=”System.Security.PermissionSet” version=”1”
ID=”Custom” SameSite=”site” Unrestricted=”true”/>
2. In the project file (with the .csproj or .vbproj extension),change
<TargetZone>Internet</TargetZone>
to
<TargetZone>Custom</TargetZone>
You can also make this change inside Visual Studio’s project properties UI on the
Security tab.
WPF unleashed, page 231
How to enable our own library to run in the WPF browser application.
You use the same mechanism that applies to all .NET components. If you mark an assembly
with the AllowPartiallyTrustedCallers attribute and install it into the Global Assembly
Cache (which can only be done if the user trusts your code and decides to run it),any of the
assembly’s public APIs can be called by any XBAP
WPF unleashed, page 230
Nonrectangular Window, Irregular Window
<Window x:Class="MyWpfSample.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
AllowsTransparency="True" WindowStyle="None" Background="Transparent"
Title="Window1" Height="300" Width="300"
MouseLeftButtonDown="Window_MouseLeftButtonDown">
<Grid>
<Ellipse Fill="Red" Opacity="0.5" Margin="20">
<Ellipse.BitmapEffect>
<DropShadowBitmapEffect/>
</Ellipse.BitmapEffect>
</Ellipse>
<Button Margin="100" Click="Button_Click">Close</Button>
</Grid>
</Window>
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
private void Window_MouseLeftButtonDown(object sender, MouseButtonEventArgs e)
{
this.DragMove();
}
private void Button_Click(object sender, RoutedEventArgs e)
{
this.Close();
}
}
Referenced from book WPF unleashed, page225.
WPF Hook Message
IntPtr hwnd = new WindowInteropHelper(this).Handle;
HwndSource.FromHwnd(hwnd).AddHook(new HwndSourceHook(WndProc));
private IntPtr WndProc(IntPtr hwnd, int msg, IntPtr wParam, IntPtr lParam, ref bool handled)
{
if (msg == WM_PAINT)
{
//Do some extra actions.
}
return IntPtr.Zero;
}
Edit Page: PageFunction
http://msdn.microsoft.com/en-us/library/ms615540.aspx
Below is a simple sample.
PageFunction:
<PageFunction
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:sys="clr-namespace:System;assembly=mscorlib"
x:Class="NavigateSample.PageFunction1"
x:TypeArguments="sys:String"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300"
Title="PageFunction1">
<Grid>
</Grid>
</PageFunction>
Show page and get result:
//Instantiate the edit page.
PageFunction1 editPage = new PageFunction1();
//Show the page.
this.NavigationService.Navigate(editPage);
//Get returned result.
string result;
editPage.Return += new ReturnEventHandler<string>((object obj, ReturnEventArgs<string> arg)=>
{
result = arg.Result;
});
Have one Frame Navigate to Another Page
<TextBlock Height="23" HorizontalAlignment="Left" Margin="66,66,0,0" Name="textBlock1" VerticalAlignment="Top" Width="278" >
Click <Hyperlink NavigateUri="Page2.xaml">Page2</Hyperlink>
<Hyperlink NavigateUri="Page3.xaml" TargetName="frame">Have frame navigate to another page.</Hyperlink>
</TextBlock>
<Frame Name="frame" Source="Page2.xaml" Margin="66,118,137,52" />
Notes about Application
1. The event fired when the current user logs off or shuts down the computer: SessionEnding
http://msdn.microsoft.com/en-us/library/system.windows.application.sessionending.aspx
2. Some properties about window: Windows, MainWindow
http://msdn.microsoft.com/en-us/library/system.windows.application.windows.aspx
http://msdn.microsoft.com/en-us/library/system.windows.application.mainwindow.aspx
3. Customerize how to exit an application: ShutdownMode
http://msdn.microsoft.com/en-us/library/system.windows.application.shutdownmode.aspx
4. Start window: StartupUri
http://msdn.microsoft.com/en-us/library/system.windows.application.startupuri.aspx
5. A dictionary for the windows to share information: Properties
http://msdn.microsoft.com/en-us/library/system.windows.application.properties.aspx
Wednesday, December 16, 2009
How to set StartUri in WPF
We only need to add the directory path before the window xaml file name, such as "Palyer/MyPlayerWindow.xaml" or "Palyer\MyPlayerWindow.xaml".
