Skip to content

Instantly share code, notes, and snippets.

@niko86
Created March 8, 2020 10:13
Show Gist options
  • Save niko86/c430a513ccc31e2ec70cc9e905ef379d to your computer and use it in GitHub Desktop.
Save niko86/c430a513ccc31e2ec70cc9e905ef379d to your computer and use it in GitHub Desktop.
import os
import sys
sys.path.append(os.getcwd())
import clr
clr.AddReference('wpf\PresentationFramework')
from System import String
from System.IO import StreamReader
from System.Threading import ApartmentState, Thread, ThreadStart
from System.Windows import Application, LogicalTreeHelper, Window
from System.Windows.Markup import XamlReader
clr.AddReference('System.Collections')
from System.Windows.Controls import *
from System.Collections.Generic import *
from System.Windows.Data import Binding
class MyData(object):
def __init__(self, name):
self.name = name
class MyWindow(Window):
def __init__(self):
stream = StreamReader('example.xaml')
window = XamlReader.Load(stream.BaseStream)
TestDataGrid = LogicalTreeHelper.FindLogicalNode(window, "TestDataGrid")
items = []
items.append(MyData("Sam"))
items.append(MyData("Bob"))
TestDataGrid.ItemsSource = items
Application().Run(window)
if __name__ == '__main__':
thread = Thread(ThreadStart(MyWindow))
thread.SetApartmentState(ApartmentState.STA)
thread.Start()
thread.Join()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment