Bug: WMC1510 appearing but x:Bind is used
Description
Despite using {x:Bind ViewModel.x} the WMC1510 analyzer flags my XAML code. Apps works fine but the warning comes up when the app gets compiled.
Steps To Reproduce
- Create new App
- Use the following XAML Code
<ComboBox x:Name="ThemeMode"
ItemsSource="{x:Bind ViewModel.Themes, Mode=OneWay}"
DisplayMemberPath="DisplayName"
SelectedValuePath="Value"
SelectedValue="{x:Bind ViewModel.SelectedTheme, Mode=TwoWay}"
PlaceholderText="Select Theme" />
- Use the following C# Code
public sealed partial class SettingsPageViewModel : ObservableObject
{
[ObservableProperty]
public partial ElementTheme SelectedTheme { get; set; } = ElementTheme.Default;
public ObservableCollection<ThemeModel> Themes { get; } =
[
new(nameof(ElementTheme.Light), ElementTheme.Light),
new(nameof(ElementTheme.Dark), ElementTheme.Dark),
new(nameof(ElementTheme.Default), ElementTheme.Default)
];
}
[GeneratedBindableCustomProperty]
public sealed partial class ThemeModel(string displayName, ElementTheme value)
{
public string DisplayName { get; init; } = displayName;
public ElementTheme Value { get; init; } = value;
}
- Compile once
- See warning in output window (and then in error list if enabled)
Expected Behavior
The analyzer not flagging my code or some explanation why it does (and maybe how to correct my mistake).
Version Info
.NET SDK 9.0.201 Microsoft.CsWinRT 2.2.0 Microsoft.WindowsAppSDK 1.7.250208002-preview1
Additional Context
Interestingly this warning only occurs when the building of the application is done, not when it's just designed in the IDE.
I also tried to specify x:DataType like it's said in the description but somehow I can't find a spot where it doesn't gets flagged as an error.
The warning is showing because of your DisplayMemberPath="DisplayName". I think you need to use this attribute on your ViewModel class:
[WinRT.GeneratedBindableCustomProperty([nameof(DisplayName)], [typeof(string)])]
The warning is showing because of your
DisplayMemberPath="DisplayName". I think you need to use this attribute on your ViewModel class:[WinRT.GeneratedBindableCustomProperty([nameof(DisplayName)], [typeof(string)])]
Sadly this doesn't help, the warning is still shown.
I didn't test with ComboBox, but I assume you'd have to do the same thing for SelectedValuePath & Value, so something like
[WinRT.GeneratedBindableCustomProperty([nameof(DisplayName), nameof(Value)], [typeof(string), typeof(string)])]
Sadly this doesn't help, the warning is still shown.
The warning doesn't disappear but you can ignore it if you configured it correctly AFAIK.
The warning disappeared for me after I used the GeneratedBindableCustomProperty
Sadly this doesn't help, the warning is still shown.
The warning doesn't disappear but you can ignore it if you configured it correctly AFAIK.
The example in the initial post still works so that's no issue at all. The warning is still there but I ignore it for now.