Skip to content
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

[RelativeSource] Inconsistency involving Self between Uno and Windows #16940

Closed
eriklimakc opened this issue May 30, 2024 · 4 comments
Closed
Assignees
Labels
kind/bug Something isn't working

Comments

@eriklimakc
Copy link
Contributor

eriklimakc commented May 30, 2024

Current behavior

There is a different behavior between Windows and Uno.

Given the repo/example below RelativeSource as TemplatedParent works on Windows but not on Uno (fixed)
where RelativeSource as Self works on Uno but not on Windows.

Expected behavior

Same behavior in all platforms.

How to reproduce it (as minimally and precisely as possible)

Binding Sample Draft PR - unoplatform/Uno.Samples#681

Or

<Page.DataContext>
    <local:MainViewModel />
</Page.DataContext>

<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
    <ListView ItemsSource="{Binding Items}">
        <ListView.ItemTemplate>
            <DataTemplate>
                <StackPanel Orientation="Horizontal" Spacing="8">
                    <TextBlock VerticalAlignment="Center" Text="{Binding Text}" />

                    <!--  RelativeSource as TemplatedParent works on Windows but not on Uno  -->
                    <!--  RelativeSource as Self works on Uno but not on Windows  -->
                    <Button Command="{utu:ItemsControlBinding Path=DataContext.RemoveItemCommand}"
                            CommandParameter="{Binding DataContext, RelativeSource={RelativeSource Mode=Self}}"
                            Content="Delete" />

            </DataTemplate>
        </ListView.ItemTemplate>
    </ListView>
</StackPanel>
public partial class MainViewModel : ObservableObject
{
    [ObservableProperty]
    private ObservableCollection<Item> items;

    public ICommand RemoveItemCommand { get; }

    public MainViewModel()
    {
        Items =
        [
            new Item { Text = "Item 1" },
            new Item { Text = "Item 2" },
            new Item { Text = "Item 3" }
        ];

        RemoveItemCommand = new RelayCommand<Item>(RemoveItem, i => i is not null && Items.Contains(i));
    }

    private void RemoveItem(Item? item)
    {
        Items.Remove(item!);
    }
}

public class Item
{
    public string? Text { get; set; }
}

Works on UWP/WinUI

Yes

@eriklimakc eriklimakc added kind/bug Something isn't working triage/untriaged Indicates an issue requires triaging or verification difficulty/tbd Categorizes an issue for which the difficulty level needs to be defined. labels May 30, 2024
@eriklimakc
Copy link
Contributor Author

#12732 Should fix this.

@agneszitte
Copy link
Contributor

agneszitte commented May 30, 2024

@jeromelaban, @MartinZikmund, @dansiegel (cc @Xiaoy312)
I will let you check the priority of this issue
Related PR: unoplatform/uno.extensions#2292

@MartinZikmund MartinZikmund added triage/potentially-fixed Categorizes an issue as potentially fixed by some unlinked PR, fix needs to be verified and removed triage/untriaged Indicates an issue requires triaging or verification difficulty/tbd Categorizes an issue for which the difficulty level needs to be defined. labels Oct 9, 2024
@MartinZikmund
Copy link
Member

@morning4coffe-dev this may be fixed now with #17645 , can you check please?

@morning4coffe-dev
Copy link
Member

@MartinZikmund, @Xiaoy312, @eriklimakc I can confirm that TemplatedParent as a source now works on Uno targets as well! 🎉
image
When I set it to Self, it still works on Uno only, not sure if we want to make some changes, to be inline with Windows.

@MartinZikmund MartinZikmund removed the triage/potentially-fixed Categorizes an issue as potentially fixed by some unlinked PR, fix needs to be verified label Oct 14, 2024
@MartinZikmund MartinZikmund changed the title [RelativeSource] Inconsistency involving Self and TemplatedParent between Uno and Windows [RelativeSource] Inconsistency involving Self between Uno and Windows Oct 14, 2024
@morning4coffe-dev morning4coffe-dev removed their assignment Oct 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
kind/bug Something isn't working
Projects
None yet
Development

No branches or pull requests

6 participants