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

The EditBox does not work in the ListView #19

Open
lmuestak opened this issue May 11, 2023 · 0 comments
Open

The EditBox does not work in the ListView #19

lmuestak opened this issue May 11, 2023 · 0 comments

Comments

@lmuestak
Copy link

lmuestak commented May 11, 2023

Hi there,

somehow I am not able to use the EditBox in the ListView. The EditBox can switch to the edit mode but when I commit the changes I am getting the following exception and therefore the changes cannot be committed and the focus can be set to other rows in the ListView.

Can you please help me with that issue?

Thank you so much for your help in advance!
Leon

Exception details:

System.Runtime.InteropServices.COMException HResult=0x80040206 Message=There is currently no layout available. Source=PresentationFramework Stack Trace: at System.Windows.Documents.TextStore.GetVisualInfo(PresentationSource& source, IWin32Window& win32Window, ITextView& view) at System.Windows.Documents.TextStore.GetScreenExt(Int32 viewCookie, RECT& rect)

I've extended the demo XAML as follows for you to test:

`


<Grid.Resources>
<convDemo:BoolToVisibilityConverter x:Key="boolToHiddenVisibilityConverter"
False="Hidden" True="Visible" />

        <conv:ISolutionBaseItemToImageConverter x:Key="ISolutionBaseItemToImageConverter" />
        
        <convDemo:ISolutionItemItemTypeToTupleConverter x:Key="ISolutionItemItemTypeToTupleConverter" />
        <convDemo:ItemTypeDisplayNameToTextConverter x:Key="ISolutionBaseItemToTextConverter"/>

        <Style x:Key="TreeViewStyle" TargetType="{x:Type TreeView}">
            <Setter Property="TreeView.Background" Value="Transparent"/>
            <Setter Property="VirtualizingStackPanel.IsVirtualizing" Value="True"/>
            <Setter Property="VirtualizingStackPanel.VirtualizationMode" Value="Recycling"/>
            <Setter Property="TreeView.SnapsToDevicePixels" Value="True" />
            <Setter Property="TreeView.OverridesDefaultStyle" Value="True" />
            <Setter Property="ItemsControl.ItemsPanel">
                <Setter.Value>
                    <ItemsPanelTemplate>
                        <VirtualizingStackPanel IsItemsHost="True"/>
                    </ItemsPanelTemplate>
                </Setter.Value>
            </Setter>
            <Setter Property="TreeView.Template">
                <Setter.Value>
                    <ControlTemplate TargetType="TreeView">
                        <ScrollViewer Focusable="False" CanContentScroll="True" Padding="3">
                            <ItemsPresenter HorizontalAlignment="Stretch"/>
                        </ScrollViewer>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <!-- Use a proxy to bind items to root properties of this collection -->
        <bindLocal:BindingProxy x:Key="DataContextProxy"  Data="{Binding Solution}" />

        <ControlTemplate  x:Key="TreeItemContentPresenter">
            <Grid xmlns:loc="clr-namespace:InplaceEditBoxLib.Local;assembly=InplaceEditBoxLib"
              >
                <Grid.ContextMenu>
                    <ContextMenu>
                        <MenuItem Command="{Binding Path=Data.StartRenameCommand, Source={StaticResource DataContextProxy}}"
                                      CommandParameter="{Binding}"
                                      Header="Rename"
                                      ToolTip="Rename this item"
                                      />
                        <Separator/>
                        <MenuItem Command="{Binding Path=Data.ItemAddCommand, Source={StaticResource DataContextProxy}}"
                                      Header="Add File"
                                      ToolTip="Adds a file under this item"
                                      >
                            <MenuItem.CommandParameter>
                                <MultiBinding Converter="{StaticResource ISolutionItemItemTypeToTupleConverter}">
                                    <Binding />
                                    <Binding Source="{x:Static sitemtype:SolutionItemType.File}"/>
                                </MultiBinding>
                            </MenuItem.CommandParameter>
                        </MenuItem>
                        <MenuItem Command="{Binding Path=Data.ItemAddCommand, Source={StaticResource DataContextProxy}}"
                                      Header="Add Folder"
                                      ToolTip="Adds a folder under this item">
                            <MenuItem.CommandParameter>
                                <MultiBinding Converter="{StaticResource ISolutionItemItemTypeToTupleConverter}">
                                    <Binding />
                                    <Binding Source="{x:Static sitemtype:SolutionItemType.Folder}"/>
                                </MultiBinding>
                            </MenuItem.CommandParameter>
                        </MenuItem>
                        <MenuItem Command="{Binding Path=Data.ItemAddCommand, Source={StaticResource DataContextProxy}}"
                                      Header="Add Project"
                                      ToolTip="Adds a project under this item">
                            <MenuItem.CommandParameter>
                                <MultiBinding Converter="{StaticResource ISolutionItemItemTypeToTupleConverter}">
                                    <Binding />
                                    <Binding Source="{x:Static sitemtype:SolutionItemType.Project}"/>
                                </MultiBinding>
                            </MenuItem.CommandParameter>
                        </MenuItem>
                        <Separator/>
                        <MenuItem Command="{Binding Path=Data.ItemRemoveCommand, Source={StaticResource DataContextProxy}}"
                                      CommandParameter="{Binding}"
                                      Header="Remove"
                                      ToolTip="Remove this item"
                                      />
                        <MenuItem Command="{Binding Path=Data.ItemRemoveAllCommand, Source={StaticResource DataContextProxy}}"
                                      CommandParameter="{Binding}"
                                      Header="Remove All Items"
                                      ToolTip="Remove all items below this item"
                                      />
                    </ContextMenu>
                </Grid.ContextMenu>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="Auto" />
                    <ColumnDefinition Width="*" />
                </Grid.ColumnDefinitions>

                <Image Grid.Column="0" Height="16" Margin="3,0"
                           Focusable="False"
                           Source="{Binding Converter={StaticResource ISolutionBaseItemToImageConverter}}"
                           VerticalAlignment="Center" />

                <!-- Debugging actual EditInPlace:EditBox
                <TextBlock Grid.Column="1"
                           Text="{Binding Path=DisplayName, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
                           ToolTip="{Binding Description, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
                           /-->
                
                <EditInPlace:EditBox Grid.Column="1" Name="EditItemBox"
                                         Text="{Binding Path=DisplayName, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
                                         ToolTip="{Binding Description, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
                                         Focusable="True"
                                
                                         VerticalAlignment="Stretch"
                                         HorizontalAlignment="Left"
                                         IsReadOnly="{Binding IsReadOnly}"
                                         RenameCommand="{Binding Path=Data.RenameCommand, Source={StaticResource DataContextProxy}}"
                                         RenameCommandParameter="{Binding}"
                                         ToolTipService.ShowOnDisabled="True"
                                         InvalidInputCharacters="{x:Static loc:Strings.ForbiddenRenameKeys}"
                                         InvalidInputCharactersErrorMessage="{x:Static loc:Strings.ForbiddenRenameKeysMessage}"
                                         InvalidInputCharactersErrorMessageTitle="{x:Static loc:Strings.ForbiddenRenameKeysTitle}"
                                         Margin="2,0"
                                         >
                    <EditInPlace:EditBox.DisplayText>
                        <MultiBinding Converter="{StaticResource ISolutionBaseItemToTextConverter}">
                            <Binding Path="DisplayName"/>
                            <Binding Path="ItemType"/>
                        </MultiBinding>
                    </EditInPlace:EditBox.DisplayText>
                </EditInPlace:EditBox>
                <!-- Its important to use margin Margin="2,0" since overlay will otherwise not work -->
            </Grid>
        </ControlTemplate>

        <DataTemplate x:Key="TreeItemTemplate">
            <ContentControl Template="{StaticResource TreeItemContentPresenter}" />
        </DataTemplate>
        <HierarchicalDataTemplate x:Key="ChildrenItem" ItemsSource="{Binding Children}">
            <ContentControl Template="{StaticResource TreeItemContentPresenter}" />
        </HierarchicalDataTemplate>
        <views:TreeViewItemSelector x:Key="TreeItemSelector"
                                    FileTemplate="{StaticResource TreeItemTemplate}"
                                    ChildrenItemTemplate="{StaticResource ChildrenItem}"/>
    </Grid.Resources>
    <Grid.ColumnDefinitions>
        <ColumnDefinition Width="*" />
        <ColumnDefinition Width="5" />
        <ColumnDefinition Width="*" />
    </Grid.ColumnDefinitions>
    <Grid.RowDefinitions>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="Auto"/>
        <RowDefinition Height="*"/>
    </Grid.RowDefinitions>
    <ToolBarTray Grid.Row="0" Background="Transparent">
        <ToolBar Background="Transparent">
            <Button Content="Save"
                    Command="{Binding SaveSolutionCommand}"
                    CommandParameter="{Binding Solution}"
                    ToolTip="Save solution to storage." Margin="3"/>
            
            <Button Content="Load"
                    Command="{Binding LoadSolutionCommand}"
                    CommandParameter="{Binding Solution}"
                    ToolTip="Load solution from storage."  Margin="3"/>
        </ToolBar>
    </ToolBarTray>

    <ProgressBar Height="6" Grid.Row="1" IsIndeterminate="True"
                 Visibility="{Binding IsProcessing,Mode=OneWay,UpdateSourceTrigger=PropertyChanged, Converter={StaticResource boolToHiddenVisibilityConverter}}" />

    <TreeView Grid.Row="2"
              x:Name="treeView"
              ItemsSource="{Binding Solution.Root}"
              VirtualizingStackPanel.IsVirtualizing="True"
              VirtualizingStackPanel.VirtualizationMode="Standard"
              VirtualizingStackPanel.CacheLengthUnit="Page"
              VirtualizingStackPanel.CacheLength="0,4"
              Style="{StaticResource TreeViewStyle}"
              ItemTemplateSelector="{StaticResource TreeItemSelector}"
              behav:TreeViewSelectionChangedBehavior.ChangedCommand="{Binding Solution.SelectionChangedCommand}"
              behav:TreeViewVirtualItemBehaviour.SelectedItem="{Binding Solution.SelectedItem}"
             >
        <TreeView.ItemContainerStyle>
            <Style TargetType="{x:Type TreeViewItem}" BasedOn="{StaticResource {x:Type TreeViewItem}}">
                <Style.Resources>
                    <InputBindingCollection x:Key="InputCollection" x:Shared="False">
                        <KeyBinding Key="F2"
                                    Command="{Binding Path=Data.StartRenameCommand, Source={StaticResource DataContextProxy}}"
                                    CommandParameter="{Binding Path=Data.SelectedItem, Source={StaticResource DataContextProxy}}"
                                    />
                    </InputBindingCollection>
                </Style.Resources>
                <Setter Property="behav:TreeViewItemBehaviour.IsBroughtIntoViewWhenSelected" Value="True" />
                <!-- Setter Property="behav:TreeViewItemExpanded.Command" Value="{Binding Path=Data.ExpandCommand, Source={StaticResource DataContextProxy}}" / -->
                <Setter Property="IsExpanded" Value="{Binding IsItemExpanded, Mode=TwoWay}" />
                <Setter Property="IsSelected" Value="{Binding IsItemSelected, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" />

                <!-- https://stackoverflow.com/questions/2660760/defining-inputbindings-within-a-style#7808997 -->
                <Setter Property="EditInPlace:Attach.InputBindings" Value="{DynamicResource InputCollection}" />
            </Style>
        </TreeView.ItemContainerStyle>
    </TreeView>
    <GridSplitter Grid.Column="1" Grid.Row="1" Grid.RowSpan="2" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Background="BurlyWood">
        
    </GridSplitter>
    <ListView Grid.Column="2" Grid.Row="1" Grid.RowSpan="2" ItemsSource="{Binding ElementName=treeView, Path=SelectedItem.Children}">
        <ListView.View>
            <GridView>
                <GridViewColumn Header="Name" Width="420">
                    <GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <EditInPlace:EditBox Grid.Column="1" Name="EditItemBox"
                                         Text="{Binding Path=DisplayName, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
                                         ToolTip="{Binding Description, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"
                                         Focusable="True"
                                         VerticalAlignment="Stretch"
                                         HorizontalAlignment="Left"
                                         IsReadOnly="{Binding IsReadOnly}"
                                         RenameCommand="{Binding Path=Data.RenameCommand, Source={StaticResource DataContextProxy}}"
                                         RenameCommandParameter="{Binding}"
                                         ToolTipService.ShowOnDisabled="True"
                                         Margin="2,0">
                                <EditInPlace:EditBox.DisplayText>
                                    <MultiBinding Converter="{StaticResource ISolutionBaseItemToTextConverter}">
                                        <Binding Path="DisplayName"/>
                                        <Binding Path="ItemType"/>
                                    </MultiBinding>
                                </EditInPlace:EditBox.DisplayText>
                            </EditInPlace:EditBox>
                        </DataTemplate>
                    </GridViewColumn.CellTemplate>
                </GridViewColumn>
            </GridView>
        </ListView.View>
    </ListView>
</Grid>

`

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