-
-
Notifications
You must be signed in to change notification settings - Fork 14
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
question. bind to array works ? #21
Comments
Yes, you can access elements of an array or of the Item property. The c# and xaml code in your example is not correct. You can't have named Indexer property in c#. Instead you can have something like this: public class ErrorsCollection
{
public string this[string index]
{
get => // some logic
}
}
class ViewModel
{
public ErrorsCollection ErrorOf { get; }
} <TextBlock Text="{x:Bind ViewModel.ErrorOf['Username']}"/> |
and what about IndexerName attribute ? UWP and WINUI recognize it in x:Bind class ViewModel
|
Does compiled bindings recognize [IndexerName] attribute ? |
IndexerNameAttribute currently is not supported. I'll add it in the next version. Now the property with "Item" name is searched to find the indexer property. IndexerNameAttribute is actually meant to be able to consume c# libraries in other programming languages. If your code is completely in c#, setting the attribute brings you nothing. You can’t use the name neither in standard Bindings nor in UWP/WinUI x:Binds. In your OnErrorsChanged you have to raise PropertyChanged event with empty string. For this ViewModel with indexer: public class MainViewModel : IDictionary<string, string>, INotifyPropertyChanged
{
[IndexerName("ErrorOf")]
public string this[string index] { get => ...
And for this XAML in UWP: <Grid>
<TextBlock Text="{x:Bind _viewModel['a'], Mode=OneWay}"/>
<TextBlock Text="{x:Bind _viewModel['b'], Mode=OneWay}"/>
</Grid> this PropertyChanged handler code is generated:´ public void PropertyChanged__viewModel(object sender, global::System.ComponentModel.PropertyChangedEventArgs e)
{
MainPage_obj1_Bindings bindings = TryGetBindingObject();
if (bindings != null)
{
string propName = e.PropertyName;
global::App7.MainViewModel obj = sender as global::App7.MainViewModel;
if (global::System.String.IsNullOrEmpty(propName))
{
if (obj != null)
{
bindings.Update__viewModel_K372029373(obj["a"], DATA_CHANGED);
bindings.Update__viewModel_K372029376(obj["b"], DATA_CHANGED);
}
}
else
{
switch (propName)
{
default:
break;
}
}
}
} In my CompiledBindings notifications for element access expressions are currently not supported. I will also implement it in the next version. |
Does this works with compiledbindings ?
// ViewModel
public string ErrorOf [string index]
{
// get and set accessors
}
// XAML
< textblock Text={x:Bind ViewModel.ErrorOf ["Username"]}
if yes, please considere to add binding to arrays in readme, if no please considere open an issue
UWP Bind supports bind to array property
The text was updated successfully, but these errors were encountered: