Skip to content

Commit

Permalink
Fix crashes when selecting items in Inflight and TopicExplorer pages (#…
Browse files Browse the repository at this point in the history
…101)

* Use content presenter in inflight page for selected item.

* Fix race condition in topic explorer.
  • Loading branch information
chkr1011 authored Sep 19, 2024
1 parent ddc1c76 commit b3411f9
Show file tree
Hide file tree
Showing 6 changed files with 22 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Source/Common/ViewLocator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ public Control Build(object? viewModel)
{
return new TextBlock();
}

var viewModelTypeName = viewModel.GetType().FullName!;

if (!_viewTypeCache.TryGetValue(viewModelTypeName, out var viewType))
Expand Down
2 changes: 1 addition & 1 deletion Source/Pages/Inflight/InflightPageItemViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public InflightPageItemViewModel(MqttApplicationMessage message)
}
else
{
Payload = Array.Empty<byte>();
Payload = [];
}

Length = Payload.Length;
Expand Down
13 changes: 10 additions & 3 deletions Source/Pages/Inflight/InflightPageView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@
<!-- The data grid with items -->
<DataGrid Grid.Column="0"
Background="#262626"
SelectedItem="{CompiledBinding SelectedItem}"
x:Name="PART_Items"
ItemsSource="{CompiledBinding Items, Mode=OneTime}">
<DataGrid.Columns>
<!-- The number column -->
Expand Down Expand Up @@ -139,8 +139,15 @@
Content="Selected message" />
</Border>

<inflight:InflightPageItemView Grid.Row="1"
DataContext="{CompiledBinding SelectedItem}" />
<ContentPresenter Grid.Row="1"
Content="{Binding ElementName=PART_Items, Path=SelectedItem}">
<!-- It seems we need the data template here even if it works without such a template in other areas!? -->
<ContentPresenter.ContentTemplate>
<DataTemplate DataType="{x:Type inflight:InflightPageItemViewModel}">
<inflight:InflightPageItemView />
</DataTemplate>
</ContentPresenter.ContentTemplate>
</ContentPresenter>

</Grid>
</Grid>
Expand Down
8 changes: 0 additions & 8 deletions Source/Pages/Inflight/InflightPageViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ public sealed class InflightPageViewModel : BasePageViewModel
string? _filterText;
bool _isRecordingEnabled = true;

InflightPageItemViewModel? _selectedItem;

public InflightPageViewModel(MqttClientService mqttClientService, InflightPageItemExportService exportService)
{
_mqttClientService = mqttClientService ?? throw new ArgumentNullException(nameof(mqttClientService));
Expand Down Expand Up @@ -64,12 +62,6 @@ public bool IsRecordingEnabled

public ReadOnlyObservableCollection<InflightPageItemViewModel> Items => _items;

public InflightPageItemViewModel? SelectedItem
{
get => _selectedItem;
set => this.RaiseAndSetIfChanged(ref _selectedItem, value);
}

public Task AppendMessage(MqttApplicationMessage message)
{
if (message == null)
Expand Down
12 changes: 9 additions & 3 deletions Source/Pages/TopicExplorer/TopicExplorerItemView.axaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@

<!-- Messages -->
<DataGrid Grid.Row="1"
x:Name="PART_Items"
ItemsSource="{CompiledBinding Messages, Mode=OneTime}"
SelectedItem="{CompiledBinding SelectedMessage, Mode=TwoWay}"
Margin="0,0,0,10">
Expand Down Expand Up @@ -98,9 +99,14 @@
Classes="grid_splitter_vertical" />

<!-- Message details -->
<inflight:InflightPageItemView Grid.Row="3"
DataContext="{CompiledBinding SelectedMessage.InflightItem, FallbackValue={x:Null}}" />
<ContentPresenter Content="{Binding ElementName=PART_Items, Path=SelectedItem.InflightItem}"
Grid.Row="3">
<ContentPresenter.ContentTemplate>
<DataTemplate DataType="{x:Type inflight:InflightPageItemViewModel}">
<inflight:InflightPageItemView />
</DataTemplate>
</ContentPresenter.ContentTemplate>
</ContentPresenter>
</Grid>


</UserControl>
1 change: 1 addition & 0 deletions Source/mqttMultimeter.sln.DotSettings
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,7 @@
<s:Boolean x:Key="/Default/Environment/SettingsMigration/IsMigratorApplied/=JetBrains_002EReSharper_002EPsi_002ECSharp_002ECodeStyle_002ESettingsUpgrade_002EMigrateBlankLinesAroundFieldToBlankLinesAroundProperty/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=Avalonia/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=CONNACK/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=inflight/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=PINGREQ/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=PINGRESP/@EntryIndexedValue">True</s:Boolean>
<s:Boolean x:Key="/Default/UserDictionary/Words/=PUBACK/@EntryIndexedValue">True</s:Boolean>
Expand Down

0 comments on commit b3411f9

Please sign in to comment.