Skip to content

Instantly share code, notes, and snippets.

@niko86
Created March 8, 2020 08:59
Show Gist options
  • Save niko86/e80f3fe5984168a8d82c249d190e9abd to your computer and use it in GitHub Desktop.
Save niko86/e80f3fe5984168a8d82c249d190e9abd 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.IO import StreamReader
from System.Threading import ApartmentState, Thread, ThreadStart
from System.Windows import Application, LogicalTreeHelper, Window
from System.Windows.Markup import XamlReader
from System.Windows.Controls import *
clr.AddReference('System.Collections')
from System.Collections.Generic import *
from System.Windows.Data import Binding
class MyWindow(Window):
def __init__(self):
stream = StreamReader('example.xaml')
window = XamlReader.Load(stream.BaseStream)
TestDataGrid = LogicalTreeHelper.FindLogicalNode(window, "TestDataGrid")
col1 = DataGridTextColumn()
col1.Header = "Name"
col1.Binding = Binding("name")
TestDataGrid.Columns.Add(col1)
names = List[str]()
names.Add("Sam")
names.Add("Carla")
TestDataGrid.ItemsSource = names
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