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

Fixes for: OperationsMenuView.axaml and OperationsMenuViewModel.cs #1

Open
Noemata opened this issue Oct 11, 2024 · 0 comments
Open

Comments

@Noemata
Copy link

Noemata commented Oct 11, 2024

Change OperationsMenuView.axaml to:

<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:local="clr-namespace:Nodify.Avalonia.Calculator.ViewModels"
             mc:Ignorable="d" d:DesignWidth="800" d:DesignHeight="450"
             x:Class="Nodify.Avalonia.Calculator.Views.OperationsMenuView"
             x:DataType="local:OperationsMenuViewModel"
             Bounds="{Binding Bounds,Mode=OneWayToSource}">

	<UserControl.Resources>
		<ControlTheme TargetType="{x:Type TextBlock}" x:Key="{x:Type TextBlock}">
			<Setter Property="Foreground"
                    Value="{DynamicResource ForegroundBrush}" />
		</ControlTheme>
	</UserControl.Resources>

  <!--
  <UserControl.Styles>
    <Style Selector="TextBlock">
        <Setter Property="Foreground"
                Value="{DynamicResource ForegroundBrush}" />
    </Style>
  </UserControl.Styles>
  -->

    <Border Padding="7"
            CornerRadius="3"
            Background="{DynamicResource Node.BackgroundBrush}"
            BorderBrush="{DynamicResource NodifyEditor.SelectionRectangleStrokeBrush}"
            BorderThickness="2"
            IsVisible="{Binding IsVisible}">
        <Grid>
            <Grid.RowDefinitions>
                <RowDefinition Height="Auto" />
                <RowDefinition Height="*" />
            </Grid.RowDefinitions>

            <ItemsControl Grid.Row="1" 
                          ItemsSource="{Binding AvailableOperations}">
                <ItemsControl.ItemTemplate>
                    <DataTemplate DataType="{x:Type local:OperationInfoViewModel}">
						<!--
                        xmlns:view="clr-namespace:Nodify.Avalonia.Calculator.Views"
						Command="{Binding ((local:OperationsMenuViewModel)DataContext).CreateOperationCommand, RelativeSource={RelativeSource AncestorType=view:OperationsMenuView}}"
                        Command="{Binding ((local:OperationsMenuViewModel)DataContext).CreateOperationCommand, RelativeSource={RelativeSource AncestorType=UserControl}}"
						Why does below not work?
                        Command="{Binding DataContext.CreateOperationCommand, RelativeSource={RelativeSource AncestorType=UserControl}}"
						-->
						<Button Content="{Binding Title}"
                                Command="{Binding ((local:OperationsMenuViewModel)DataContext).CreateOperationCommand, RelativeSource={RelativeSource AncestorType=UserControl}}"
                                CommandParameter="{Binding}"
                                Background="Transparent"
                                BorderBrush="Transparent"
                                Foreground="{DynamicResource ForegroundBrush}"
                                Padding="3"
                                Cursor="Hand"
                                HorizontalContentAlignment="Left">
							<Button.Theme>
								<ControlTheme TargetType="{x:Type Button}">
									<Setter Property="Template">
										<Setter.Value>
											<ControlTemplate TargetType="{x:Type Button}">
												<Border Name="Border"
                                                        Background="{TemplateBinding Background}"
                                                        Padding="{TemplateBinding Padding}">
													<ContentPresenter Content="{TemplateBinding Content}" ContentTemplate="{TemplateBinding ContentTemplate}" />
												</Border>
											</ControlTemplate>
										</Setter.Value>
									</Setter>
									<Style Selector="^:pointerover /template/ Border#Border">
										<Setter Property="Background"
                                                Value="{DynamicResource NodeInput.BorderBrush}" />
									</Style>
								</ControlTheme>
							</Button.Theme>
							<!--
                            <Button.Styles>
                                <Style Selector="Button">
                                    <Setter Property="Template">
                                        <Setter.Value>
                                            <ControlTemplate TargetType="{x:Type Button}">
                                                <Border Name="Border"
                                                        Background="{TemplateBinding Background}"
                                                        Padding="{TemplateBinding Padding}">
                                                    <ContentPresenter Content="{TemplateBinding Content}"
                                                                      ContentTemplate="{TemplateBinding ContentTemplate}"/>
                                                </Border>
                                            </ControlTemplate>
                                        </Setter.Value>
                                    </Setter>
                                    <Style Selector="^ :pointerover /template/ Border#Border">
                                        <Setter Property="Background"
                                                Value="{DynamicResource NodeInput.BorderBrush}" />
                                    </Style>
                                </Style>
                            </Button.Styles>
							-->
                        </Button>
                    </DataTemplate>
                </ItemsControl.ItemTemplate>
            </ItemsControl>
        </Grid>
    </Border>
</UserControl>

In OperationsMenuViewModel.cs:

remove unused -> private Rect _bounds;

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

No branches or pull requests

1 participant