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

“ContextMenu” use “ItemsSource”,Header Binding error #359

Closed
chenjunr opened this issue May 19, 2024 · 1 comment · Fixed by #367
Closed

“ContextMenu” use “ItemsSource”,Header Binding error #359

chenjunr opened this issue May 19, 2024 · 1 comment · Fixed by #367
Assignees

Comments

@chenjunr
Copy link

use semi 11.0.7.3
image

image

if remove semi

image

this is my code

//App.axaml
<Application
    x:Class="AvaloniaApplication1.App"
    xmlns="https://github.com/avaloniaui"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    RequestedThemeVariant="Default">
    <!--  "Default" ThemeVariant follows system theme variant. "Dark" or "Light" are other available options.  -->

    <Application.Styles>
        <FluentTheme />
        <StyleInclude Source="avares://Semi.Avalonia/Themes/Index.axaml" />
        
    </Application.Styles>
</Application>

//MainViewModel.cs
using System.Collections.ObjectModel;

namespace AvaloniaApplication1.ViewModels;

public class MainViewModel : ViewModelBase
{
    public ObservableCollection<DeviceTest> DevInputListTest { get; set; }
    public string Greeting => "Welcome to Avalonia!";

    public MainViewModel()
    {
        DevInputListTest = new ObservableCollection<DeviceTest>
{            new DeviceTest { Name = "Device 1" },
            new DeviceTest { Name = "Device 2" },
            new DeviceTest { Name = "Device 3" }
        };
    }
}


public class DeviceTest {
    public string Name { get; set; }
}
//MainView.axaml
<UserControl xmlns="https://github.com/avaloniaui"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
             xmlns:vm="clr-namespace:AvaloniaApplication1.ViewModels"
             mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
             x:Class="AvaloniaApplication1.Views.MainView"
             x:DataType="vm:MainViewModel">
  <Design.DataContext>
    <!-- This only sets the DataContext for the previewer in an IDE,
         to set the actual DataContext for runtime, set the DataContext property in code (look at App.axaml.cs) -->
    <vm:MainViewModel />
  </Design.DataContext>
	<Grid>
		<Grid.ContextMenu>
			<ContextMenu ItemsSource="{Binding DevInputListTest}">
				<ContextMenu.ItemTemplate>
					<DataTemplate>
						<MenuItem Header="{Binding Name}"/>
					</DataTemplate>
				</ContextMenu.ItemTemplate>
			</ContextMenu>
		</Grid.ContextMenu>
		
		<TextBlock Text="{Binding Greeting}" HorizontalAlignment="Center" VerticalAlignment="Center"/>
	</Grid>

</UserControl>
@rabbitism
Copy link
Member

top level menu still missing template.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants