Skip to content

Commit b0de94e

Browse files
denfromufaden-run-ai
denfromufa
authored andcommitted
WPF DynamicGrid python and XAML layout files
1 parent 6e4c8bb commit b0de94e

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

demo/DynamicGrid.py

+37
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import clr
2+
import sys
3+
if sys.platform.lower() not in ['cli','win32']:
4+
print("only windows is supported for wpf")
5+
try:
6+
ironpy = sys.implementation.name.lower() == "ironpython"
7+
except:
8+
ironpy = False
9+
if ironpy:
10+
import wpf
11+
else:
12+
clr.AddReference(r"wpf\PresentationFramework")
13+
from System.IO import StreamReader
14+
from System.Windows.Markup import XamlReader
15+
from System.Threading import Thread, ThreadStart, ApartmentState
16+
17+
from System.Windows import Application, Window
18+
19+
20+
class MyWindow(Window):
21+
def __init__(self):
22+
if ironpy:
23+
wpf.LoadComponent(self, "DynamicGrid.xaml")
24+
else:
25+
stream = StreamReader("DynamicGrid.xaml")
26+
window = XamlReader.Load(stream.BaseStream)
27+
Application().Run(window)
28+
29+
30+
if __name__ == '__main__':
31+
if ironpy:
32+
Application().Run(MyWindow())
33+
else:
34+
thread = Thread(ThreadStart(MyWindow))
35+
thread.SetApartmentState(ApartmentState.STA)
36+
thread.Start()
37+
thread.Join()

demo/DynamicGrid.xaml

+34
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
<Window
2+
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
3+
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
4+
Title="WpfApplication1" Height="300" Width="300">
5+
<Grid>
6+
<Grid.RowDefinitions>
7+
<RowDefinition Height="*"/>
8+
<RowDefinition Height="Auto"/>
9+
<RowDefinition Height="*"/>
10+
</Grid.RowDefinitions>
11+
<Grid.ColumnDefinitions>
12+
<ColumnDefinition Width="*"/>
13+
<ColumnDefinition Width="Auto"/>
14+
<ColumnDefinition Width="*"/>
15+
</Grid.ColumnDefinitions>
16+
<Label Content="Left" Grid.Column="0" Background="LightBlue" />
17+
<GridSplitter
18+
VerticalAlignment="Stretch"
19+
HorizontalAlignment="Stretch"
20+
Grid.Column="1"
21+
Width="5"
22+
Grid.RowSpan="3"/>
23+
<Label Content="Right" Grid.Column="2" Grid.Row="2" Background="LightBlue" />
24+
<Label Content="Top" Grid.Column="2" Background="LightGreen"/>
25+
<GridSplitter
26+
HorizontalAlignment="Stretch"
27+
VerticalAlignment="Stretch"
28+
Grid.Row="1"
29+
Width="Auto"
30+
Height="5"
31+
Grid.ColumnSpan="3"/>
32+
<Label Content="Bottom" Grid.Column="0" Grid.Row="2" Background="LightGreen" />
33+
</Grid>
34+
</Window>

0 commit comments

Comments
 (0)