C
C#14mo ago
Ikarmus

❔ Entry Binding in custom control doesn't work

Hi, I'm making simple app in MAUI, tried to create separate control for reusability purpose. My problem is related to binding model data - changes I make in view doesn't reflect inside my data. It looks like I'm using copy of the object, but debugger pointed BindingContext obj to my backend-data.
4 Replies
Ikarmus
IkarmusOP14mo ago
No description
Ikarmus
IkarmusOP14mo ago
No description
Ikarmus
IkarmusOP14mo ago
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="blurred.Views.FeatureEditorPage"
xmlns:vm="clr-namespace:blurred.ViewModels"
xmlns:cc="clr-namespace:blurred.CustomControls"
x:DataType="vm:FeatureEditorViewModel"
Title="AddFeaturePage">
<VerticalStackLayout Padding="10">

<cc:SizePicker x:Name="fe_SizePicker"
BindingContext="{Binding EditorElement, Mode=TwoWay}" />
...
<?xml version="1.0" encoding="utf-8" ?>
<ContentPage xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
x:Class="blurred.Views.FeatureEditorPage"
xmlns:vm="clr-namespace:blurred.ViewModels"
xmlns:cc="clr-namespace:blurred.CustomControls"
x:DataType="vm:FeatureEditorViewModel"
Title="AddFeaturePage">
<VerticalStackLayout Padding="10">

<cc:SizePicker x:Name="fe_SizePicker"
BindingContext="{Binding EditorElement, Mode=TwoWay}" />
...
My View with embedded SizePicker
<?xml version="1.0" encoding="utf-8" ?>
<ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:model="clr-namespace:blurred.Models"
x:Class="blurred.CustomControls.SizePicker"
x:DataType="model:BuildingElement">
<VerticalStackLayout>
<Border StrokeThickness="2" Stroke="Coral">
<CollectionView ItemsSource="{Binding Corners, Mode=TwoWay}">
<CollectionView.Header>
<Label Text="Size picker" />
</CollectionView.Header>
<CollectionView.ItemTemplate>
<DataTemplate x:DataType="Point">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Entry Text="{Binding X, Mode=TwoWay}" Keyboard="Numeric"
Grid.Column="1" Completed="Entry_Completed" />
<Entry Text="{Binding Y, Mode=TwoWay}" Keyboard="Numeric"
Grid.Column="2" />
...
<?xml version="1.0" encoding="utf-8" ?>
<ContentView xmlns="http://schemas.microsoft.com/dotnet/2021/maui"
xmlns:x="http://schemas.microsoft.com/winfx/2009/xaml"
xmlns:model="clr-namespace:blurred.Models"
x:Class="blurred.CustomControls.SizePicker"
x:DataType="model:BuildingElement">
<VerticalStackLayout>
<Border StrokeThickness="2" Stroke="Coral">
<CollectionView ItemsSource="{Binding Corners, Mode=TwoWay}">
<CollectionView.Header>
<Label Text="Size picker" />
</CollectionView.Header>
<CollectionView.ItemTemplate>
<DataTemplate x:DataType="Point">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="*" />
</Grid.ColumnDefinitions>
<Entry Text="{Binding X, Mode=TwoWay}" Keyboard="Numeric"
Grid.Column="1" Completed="Entry_Completed" />
<Entry Text="{Binding Y, Mode=TwoWay}" Keyboard="Numeric"
Grid.Column="2" />
...
SizePicker control markup My question How to properly bind this control into view? I have done binding in other places in project, but not inside custom control, should I implement BindingProperty as in MAUI tutorial ? Now I can see that's not the issue with my custom control, because grabbing it's code inside the view didn't resolve anything It could be important that the Corners is List<Point> (which are structs), not sure if it matters in terms of binding
Accord
Accord14mo ago
Looks like nothing has happened here. I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server