silverlight etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster
silverlight etiketine sahip kayıtlar gösteriliyor. Tüm kayıtları göster

16 Mayıs 2010 Pazar

Determine ChildWindow Position At Runtime

  private FrameworkElement root;
private FrameworkElement contentroot;
private FrameworkElement chrome;

private Point childWindowOffset;


 



public MyChildWindow()
{
InitializeComponent();
Loaded
+= new RoutedEventHandler(ThisChildWindow_Loaded);
}


 



In the RoutedEventHandler ThisChildWindow_Loaded we get access with VisualTreeHelper on the VisualTree of the control template and doing so we assign to our three variables root, contentroot and chrome the corresponding element parts of the control template. To the MouseButtonEventHandler of the chrome we add a further MouseLeftButtonUpEvent called Chrome_MouseLeftButtonUp using AddHandler, in which we later add our code to determine the position.



private void ThisChildWindow_Loaded  (object sender, RoutedEventArgs e )
{
if (VisualTreeHelper.GetChildrenCount(this) == 0)
{
Dispatcher.BeginInvoke(()
=> ThisChildWindow_Loaded(this, e));
return;
}
root
= (FrameworkElement)VisualTreeHelper.GetChild(this, 0);
contentroot
= root.FindName("ContentRoot") as FrameworkElement;
chrome
= root.FindName("Chrome") as FrameworkElement;
if (chrome != null)
{
chrome.AddHandler(MouseLeftButtonUpEvent,
new MouseButtonEventHandler(Chrome_MouseLeftButtonUp), true);
}
}


 



Then we must build our routine Chrome_MouseLeftButtonUp where we will call the function GetChildWindowOffset. The actual calculation of the new location takes place in the function GetChildWindowOffset. Here is the code for GetChildWindowOffset:



private void Chrome_MouseLeftButtonUp
(
object sender,
MouseButtonEventArgs e
)
{
this.childWindowOffset =
GetChildWindowOffset
(
e.GetPosition(root),
e.GetPosition(contentroot)
);
}


 



To calculate the new position in the function GetChildWindowOffset the values of X and Y of ContentRootMousePosition is subtracted from the value of X and Y value of RootMousePosition respectively:



  result.X = RootMousePosition.X - ContentrootMousePosition.X;
result.Y = RootMousePosition.Y - ContentrootMousePosition.Y;



 



reference: http://blogs.windowsclient.net/silverlaw/archive/2010/04/15/how-to-determine-new-childwindow-position-at-runtime-silverlight-3.aspx

Silverlight GridSplitter Control

<UserControl
xmlns:basics="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
x:Class="GridSplitter2.Page"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Width="400" Height="300">
<Grid x:Name="LayoutRoot" ShowGridLines="True" Background="White" Width="400" Height="300">
<Grid.RowDefinitions>
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="Auto"/>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<basics:GridSplitter x:Name="grsplSplitter" Grid.Row="0" Grid.Column="1" VerticalAlignment
="Stretch" HorizontalAlignment="Center" Background="Aqua" Width="5"></basics:GridSplitter>
</Grid>
</UserControl>



 



Capture1



<Grid.ColumnDefinitions>
<ColumnDefinition />
<ColumnDefinition Width="25"/>
<ColumnDefinition />
</Grid.ColumnDefinitions>


 



Capture2



<UserControl
xmlns:basics="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls"
x:Class
="GridSplitter2.Page"
xmlns
="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x
="http://schemas.microsoft.com/winfx/2006/xaml"
Width
="400" Height="300">
<Grid x:Name="LayoutRoot" ShowGridLines="True" Background="White" Width="400" Height="300">
<Grid.RowDefinitions>
<RowDefinition />
<RowDefinition Height="Auto" />
<RowDefinition />
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition />
</Grid.ColumnDefinitions>
<basics:GridSplitter x:Name="grsplSplitter" Grid.Row="1" Grid.Column="0" VerticalAlignment="Center" HorizontalAlignment="Stretch" Background="Aqua" Height="5"></basics:GridSplitter>
</Grid>
</UserControl>


 



<basics:GridSplitter ShowsPreview="True" x:Name="grsplSplitter" Grid.Row="0" Grid.Column="1" VerticalAlignment="Stretch" HorizontalAlignment="Center" Background="Aqua" Width="5"></basics:GridSplitter>


 



Capture5



 



refernce: http://www.silverlightshow.net/items/Using-the-GridSplitter-control-in-Silverlight-2-Beta-1.aspx

Silverlight Grid Control

<Grid x:Name="LayoutRoot" Background="White" ShowGridLines="True">
        <Grid.RowDefinitions>
            <RowDefinition></RowDefinition>
            <RowDefinition></RowDefinition>
            <RowDefinition></RowDefinition>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition></ColumnDefinition>
            <ColumnDefinition></ColumnDefinition>
            <ColumnDefinition></ColumnDefinition>
        </Grid.ColumnDefinitions>
</Grid>

sample1_thumb

<Grid x:Name="LayoutRoot" Background="White" ShowGridLines="True">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto"></RowDefinition>
            <RowDefinition Height="100"></RowDefinition>
            <RowDefinition Height="*"></RowDefinition>
        </Grid.RowDefinitions>
        <Grid.ColumnDefinitions>
            <ColumnDefinition></ColumnDefinition>
            <ColumnDefinition></ColumnDefinition>
            <ColumnDefinition></ColumnDefinition>
        </Grid.ColumnDefinitions>
        <Button Content="Auto Size" Height="150" Grid.Row="0" Grid.Column="0" ></Button>
        <Button Content="Pixel Size" Height="150" Grid.Row="1" Grid.Column="1"></Button>
        <Button Content="Star Size" Height="150" Grid.Row="2" Grid.Column="2"></Button>
</Grid>

sample2_thumb

<RowDefinition Height="30*"></RowDefinition>
<RowDefinition Height="40*"></RowDefinition>

sample3_thumb

<Button Content="Auto Size" Height="150" Width="300" Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" ></Button>

 

reference : http://www.silverlightshow.net/items/Using-Silverlight-Grid-Control.aspx

13 Mayıs 2010 Perşembe

Silverlight xap caching?

You can turn the Enable Content Expiration HTTP header option on for your XAP file. Open IIS Manager, goto Default Web Site and find your Web site for the silverlight project. Find the XAP file under ClientBin. Goto the properties page of the XAP file, on HTTP Headers Tab, Turn on "Enable Content Expiration", click the "Expire Immediately" radio button. Save the change.

This way the new XAP (only there is a new XAP) will get downloaded when you refresh your page without having to close the browser.