Skip to content

Commit e97b4a6

Browse files
Fix mvvmtk0045 and XC0045 warnings (CommunityToolkit#2403)
* Fix mvvmtk0045 warnings Fix XamlC warning XC0045 Value not found * Fix incorrect initial bool values * Update formatting * Update Formatting * Update CustomSizeAndPositionPopupViewModel.cs --------- Co-authored-by: Brandon Minnick <13558917+brminnick@users.noreply.github.com>
1 parent 4766a14 commit e97b4a6

File tree

4 files changed

+50
-25
lines changed

4 files changed

+50
-25
lines changed

samples/CommunityToolkit.Maui.Sample/Pages/Converters/IndexToArrayItemConverterPage.xaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@
4545
Grid.Column="0"
4646
Grid.Row="2"/>
4747

48-
<Label Text="{Binding Source={x:Reference Stepper},
49-
Path=Value, StringFormat='Selected index: {0}'}"
48+
<Label x:DataType="{x:Type Stepper}"
49+
Text="{Binding Source={x:Reference Stepper}, Path=Value, StringFormat='Selected index: {0}'}"
5050
VerticalOptions="CenterAndExpand"
5151
FontAttributes="Bold"
5252
Grid.Row="2"

samples/CommunityToolkit.Maui.Sample/ViewModels/Essentials/SpeechToTextViewModel.cs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,18 @@ public partial class SpeechToTextViewModel : BaseViewModel
1717
readonly ITextToSpeech textToSpeech;
1818
readonly ISpeechToText speechToText;
1919

20+
public SpeechToTextViewModel(ITextToSpeech textToSpeech, ISpeechToText speechToText)
21+
{
22+
this.textToSpeech = textToSpeech;
23+
this.speechToText = speechToText;
24+
25+
Locales.CollectionChanged += HandleLocalesCollectionChanged;
26+
this.speechToText.StateChanged += HandleSpeechToTextStateChanged;
27+
this.speechToText.RecognitionResultCompleted += HandleRecognitionResultCompleted;
28+
}
29+
30+
public ObservableCollection<Locale> Locales { get; } = [];
31+
2032
[ObservableProperty]
2133
public partial Locale? CurrentLocale { get; set; }
2234

@@ -32,18 +44,6 @@ public partial class SpeechToTextViewModel : BaseViewModel
3244
[ObservableProperty, NotifyCanExecuteChangedFor(nameof(StopListenCommand))]
3345
public partial bool CanStopListenExecute { get; set; } = false;
3446

35-
public SpeechToTextViewModel(ITextToSpeech textToSpeech, ISpeechToText speechToText)
36-
{
37-
this.textToSpeech = textToSpeech;
38-
this.speechToText = speechToText;
39-
40-
Locales.CollectionChanged += HandleLocalesCollectionChanged;
41-
this.speechToText.StateChanged += HandleSpeechToTextStateChanged;
42-
this.speechToText.RecognitionResultCompleted += HandleRecognitionResultCompleted;
43-
}
44-
45-
public ObservableCollection<Locale> Locales { get; } = [];
46-
4747
[RelayCommand]
4848
async Task SetLocales(CancellationToken token)
4949
{

samples/CommunityToolkit.Maui.Sample/ViewModels/Views/CameraView/CameraViewViewModel.cs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ namespace CommunityToolkit.Maui.Sample.ViewModels.Views;
77

88
public partial class CameraViewViewModel(ICameraProvider cameraProvider) : BaseViewModel
99
{
10+
readonly ICameraProvider cameraProvider = cameraProvider;
11+
12+
public IReadOnlyList<CameraInfo> Cameras => cameraProvider.AvailableCameras ?? [];
13+
14+
public CancellationToken Token => CancellationToken.None;
15+
16+
public ICollection<CameraFlashMode> FlashModes { get; } = Enum.GetValues<CameraFlashMode>();
17+
1018
[ObservableProperty]
1119
public partial CameraFlashMode FlashMode { get; set; }
1220

@@ -34,12 +42,6 @@ public partial class CameraViewViewModel(ICameraProvider cameraProvider) : BaseV
3442
[ObservableProperty]
3543
public partial string ResolutionText { get; set; } = string.Empty;
3644

37-
public IReadOnlyList<CameraInfo> Cameras => cameraProvider?.AvailableCameras ?? [];
38-
39-
public CancellationToken Token => CancellationToken.None;
40-
41-
public ICollection<CameraFlashMode> FlashModes { get; } = Enum.GetValues<CameraFlashMode>();
42-
4345
[RelayCommand]
4446
async Task RefreshCameras(CancellationToken token) => await cameraProvider.RefreshAvailableCameras(token);
4547

samples/CommunityToolkit.Maui.Sample/ViewModels/Views/Popup/CustomSizeAndPositionPopupViewModel.cs

Lines changed: 28 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,17 +8,40 @@ namespace CommunityToolkit.Maui.Sample.ViewModels.Views;
88

99
public partial class CustomSizeAndPositionPopupViewModel : BaseViewModel
1010
{
11+
public IReadOnlyList<string> FlowDirectionOptions { get; } = [.. Enum.GetNames<FlowDirection>()];
12+
1113
[ObservableProperty, NotifyCanExecuteChangedFor(nameof(ExecuteShowButtonCommand))]
12-
double height = 100, width = 100;
14+
public partial double Height { get; set; } = 100;
15+
16+
[ObservableProperty, NotifyCanExecuteChangedFor(nameof(ExecuteShowButtonCommand))]
17+
public partial double Width { get; set; } = 100;
18+
19+
[ObservableProperty, NotifyCanExecuteChangedFor(nameof(ExecuteShowButtonCommand))]
20+
public partial bool IsStartHorizontalOptionSelected { get; set; } = true;
21+
22+
[ObservableProperty, NotifyCanExecuteChangedFor(nameof(ExecuteShowButtonCommand))]
23+
public partial bool IsCenterHorizontalOptionSelected { get; set; }
24+
25+
[ObservableProperty, NotifyCanExecuteChangedFor(nameof(ExecuteShowButtonCommand))]
26+
public partial bool IsEndHorizontalOptionSelected { get; set; }
1327

1428
[ObservableProperty, NotifyCanExecuteChangedFor(nameof(ExecuteShowButtonCommand))]
15-
bool isStartHorizontalOptionSelected = true, isCenterHorizontalOptionSelected, isEndHorizontalOptionSelected, isFillHorizontalOptionSelected,
16-
isStartVerticalOptionSelected = true, isCenterVerticalOptionSelected, isEndVerticalOptionSelected, isFillVerticalOptionSelected;
29+
public partial bool IsFillHorizontalOptionSelected { get; set; }
1730

1831
[ObservableProperty, NotifyCanExecuteChangedFor(nameof(ExecuteShowButtonCommand))]
19-
int flowDirectionSelectedIndex;
32+
public partial bool IsStartVerticalOptionSelected { get; set; } = true;
2033

21-
public IReadOnlyList<string> FlowDirectionOptions { get; } = Enum.GetNames<FlowDirection>().ToList();
34+
[ObservableProperty, NotifyCanExecuteChangedFor(nameof(ExecuteShowButtonCommand))]
35+
public partial bool IsCenterVerticalOptionSelected { get; set; }
36+
37+
[ObservableProperty, NotifyCanExecuteChangedFor(nameof(ExecuteShowButtonCommand))]
38+
public partial bool IsEndVerticalOptionSelected { get; set; }
39+
40+
[ObservableProperty, NotifyCanExecuteChangedFor(nameof(ExecuteShowButtonCommand))]
41+
public partial bool IsFillVerticalOptionSelected { get; set; }
42+
43+
[ObservableProperty, NotifyCanExecuteChangedFor(nameof(ExecuteShowButtonCommand))]
44+
public partial int FlowDirectionSelectedIndex { get; set; }
2245

2346
[RelayCommand(CanExecute = nameof(CanShowButtonExecute))]
2447
public Task ExecuteShowButton(CancellationToken token)

0 commit comments

Comments
 (0)