Skip to content

Commit

Permalink
WPF DynamicGrid python and XAML layout files (pythonnet#280)
Browse files Browse the repository at this point in the history
  • Loading branch information
denfromufa authored and yagweb committed Apr 7, 2017
1 parent ec86d5b commit 9afd7cf
Show file tree
Hide file tree
Showing 2 changed files with 57 additions and 0 deletions.
23 changes: 23 additions & 0 deletions demo/DynamicGrid.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import clr
import sys
if sys.platform.lower() not in ['cli','win32']:
print("only windows is supported for wpf")
clr.AddReference(r"wpf\PresentationFramework")
from System.IO import StreamReader
from System.Windows.Markup import XamlReader
from System.Threading import Thread, ThreadStart, ApartmentState
from System.Windows import Application, Window


class MyWindow(Window):
def __init__(self):
stream = StreamReader("DynamicGrid.xaml")
window = XamlReader.Load(stream.BaseStream)
Application().Run(window)


if __name__ == '__main__':
thread = Thread(ThreadStart(MyWindow))
thread.SetApartmentState(ApartmentState.STA)
thread.Start()
thread.Join()
34 changes: 34 additions & 0 deletions demo/DynamicGrid.xaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="WpfApplication1" Height="300" Width="300">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Label Content="Left" Grid.Column="0" Background="LightBlue" />
<GridSplitter
VerticalAlignment="Stretch"
HorizontalAlignment="Stretch"
Grid.Column="1"
Width="5"
Grid.RowSpan="3"/>
<Label Content="Right" Grid.Column="2" Grid.Row="2" Background="LightBlue" />
<Label Content="Top" Grid.Column="2" Background="LightGreen"/>
<GridSplitter
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
Grid.Row="1"
Width="Auto"
Height="5"
Grid.ColumnSpan="3"/>
<Label Content="Bottom" Grid.Column="0" Grid.Row="2" Background="LightGreen" />
</Grid>
</Window>

0 comments on commit 9afd7cf

Please sign in to comment.