Created
March 8, 2020 10:13
-
-
Save niko86/c430a513ccc31e2ec70cc9e905ef379d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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