-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Xaml Islands Fixes. #3206
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Xaml Islands Fixes. #3206
Changes from all commits
8464f8e
beafb0a
d3a85db
edfb11e
8b9a3ba
8f81e73
c2627ae
9362358
0d335b7
9d02ad8
572f1c5
e76b247
3dd889e
919df39
74b7c12
92f8328
d2ea666
4789686
a093bfd
7752b11
142446b
24d1b5c
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -11,10 +11,11 @@ | |
| using System.Runtime.CompilerServices; | ||
| using System.Threading; | ||
| using System.Threading.Tasks; | ||
| using Windows.ApplicationModel.Core; | ||
| using Microsoft.Toolkit.Uwp.Helpers; | ||
| using Windows.Devices.Bluetooth; | ||
| using Windows.Devices.Bluetooth.GenericAttributeProfile; | ||
| using Windows.Devices.Enumeration; | ||
| using Windows.System; | ||
| using Windows.UI.Core; | ||
| using Windows.UI.Xaml.Media.Imaging; | ||
|
|
||
|
|
@@ -134,17 +135,25 @@ public int Compare(object x, object y) | |
| private ObservableCollection<ObservableGattDeviceService> _services = | ||
| new ObservableCollection<ObservableGattDeviceService>(); | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets which DispatcherQueue is used to dispatch UI updates. | ||
| /// </summary> | ||
| public DispatcherQueue DispatcherQueue { get; set; } | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why does this need to be public?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We didn't have the requirement that this class needed to be instantiated from a UI thread. Since this might be a scenario for some users, I wanted to make sure that they could set the dispatcher if they already have an instance of it (thru the ctor), or change it later (thru the public property). |
||
|
|
||
| /// <summary> | ||
| /// Initializes a new instance of the <see cref="ObservableBluetoothLEDevice"/> class. | ||
| /// </summary> | ||
| /// <param name="deviceInfo">The device information.</param> | ||
| public ObservableBluetoothLEDevice(DeviceInformation deviceInfo) | ||
| /// <param name="dispatcherQueue">The DispatcherQueue that should be used to dispatch UI updates for this BluetoothLE Device, or null if this is being called from the UI thread.</param> | ||
| public ObservableBluetoothLEDevice(DeviceInformation deviceInfo, DispatcherQueue dispatcherQueue = null) | ||
| { | ||
| DeviceInfo = deviceInfo; | ||
| Name = DeviceInfo.Name; | ||
|
|
||
| IsPaired = DeviceInfo.Pairing.IsPaired; | ||
|
|
||
| DispatcherQueue = dispatcherQueue ?? DispatcherQueue.GetForCurrentThread(); | ||
|
|
||
| LoadGlyph(); | ||
|
|
||
| this.PropertyChanged += ObservableBluetoothLEDevice_PropertyChanged; | ||
|
|
@@ -395,7 +404,8 @@ private void ObservableBluetoothLEDevice_PropertyChanged(object sender, Property | |
| /// <exception cref="Exception">Thorws Exception when no permission to access device</exception> | ||
| public async Task ConnectAsync() | ||
| { | ||
| await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPriority.Normal, async () => | ||
| await DispatcherQueue.ExecuteOnUIThreadAsync( | ||
| async () => | ||
| { | ||
| if (BluetoothLEDevice == null) | ||
| { | ||
|
|
@@ -442,7 +452,7 @@ await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync(CoreDispatcherPrio | |
| throw new Exception(_result.ProtocolError.GetErrorString()); | ||
| } | ||
| } | ||
| }); | ||
| }, DispatcherQueuePriority.Normal); | ||
| } | ||
|
|
||
| /// <summary> | ||
|
|
@@ -468,8 +478,7 @@ public async Task DoInAppPairingAsync() | |
| /// <returns>The task of the update.</returns> | ||
| public async Task UpdateAsync(DeviceInformationUpdate deviceUpdate) | ||
| { | ||
| await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync( | ||
| CoreDispatcherPriority.Normal, | ||
| await DispatcherQueue.ExecuteOnUIThreadAsync( | ||
| () => | ||
| { | ||
| DeviceInfo.Update(deviceUpdate); | ||
|
|
@@ -479,7 +488,7 @@ await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync( | |
|
|
||
| LoadGlyph(); | ||
| OnPropertyChanged("DeviceInfo"); | ||
| }); | ||
| }, DispatcherQueuePriority.Normal); | ||
| } | ||
|
|
||
| /// <summary> | ||
|
|
@@ -512,9 +521,7 @@ protected virtual void OnPropertyChanged([CallerMemberName] string propertyName | |
| /// <param name="args">The arguments.</param> | ||
| private async void BluetoothLEDevice_NameChanged(BluetoothLEDevice sender, object args) | ||
| { | ||
| await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync( | ||
| CoreDispatcherPriority.Normal, | ||
| () => { Name = BluetoothLEDevice.Name; }); | ||
| await DispatcherQueue.ExecuteOnUIThreadAsync(() => { Name = BluetoothLEDevice.Name; }, DispatcherQueuePriority.Normal); | ||
| } | ||
|
|
||
| /// <summary> | ||
|
|
@@ -524,29 +531,27 @@ await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync( | |
| /// <param name="args">The arguments.</param> | ||
| private async void BluetoothLEDevice_ConnectionStatusChanged(BluetoothLEDevice sender, object args) | ||
| { | ||
| await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync( | ||
| CoreDispatcherPriority.Normal, | ||
| await DispatcherQueue.ExecuteOnUIThreadAsync( | ||
| () => | ||
| { | ||
| IsPaired = DeviceInfo.Pairing.IsPaired; | ||
| IsConnected = BluetoothLEDevice.ConnectionStatus == BluetoothConnectionStatus.Connected; | ||
| }); | ||
| }, DispatcherQueuePriority.Normal); | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Load the glyph for this device | ||
| /// </summary> | ||
| private async void LoadGlyph() | ||
| { | ||
| await CoreApplication.MainView.CoreWindow.Dispatcher.RunAsync( | ||
| CoreDispatcherPriority.Normal, | ||
| await DispatcherQueue.ExecuteOnUIThreadAsync( | ||
| async () => | ||
| { | ||
| var deviceThumbnail = await DeviceInfo.GetGlyphThumbnailAsync(); | ||
| var glyphBitmapImage = new BitmapImage(); | ||
| await glyphBitmapImage.SetSourceAsync(deviceThumbnail); | ||
| Glyph = glyphBitmapImage; | ||
| }); | ||
| }, DispatcherQueuePriority.Normal); | ||
| } | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why does this need to be public?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We didn't have the requirement that this class needed to be instantiated from a UI thread. Since this might be a scenario for some users, I wanted to make sure that they could set the dispatcher if they already have an instance of it (thru the ctor), or change it later (thru the public property).