Home>

I want to change the Editing Mode of multiple Ink Canvases displayed in ListView.

I am displaying multiple InkCanvas in ListView as shown in the code below.

Set the displayed InkCanvas EditingMode to the Click event of the Button control, etc.
I want to change everything at once, is it possible?

<Page.Resource>
<Style x: Key = "ListViewItemStyle" TargetType = "{x: Type ListViewItem}">
      <Setter Property = "Template">
          <Setter.Value>
              <ControlTemplate TargetType = "{x: Type ListViewItem}">
                  <DockPanel Width = "1480">
                      <InkCanvas x: Name = "InputCanvas1" Width = "240" Height = "130" VerticalAlignment = "Bottom" Background = "White" />
                      <InkCanvas x: Name = "InputCanvas2" Height = "130" VerticalAlignment = "Bottom" Background = "{x: Null}" />
                  </DockPanel>
              </ControlTemplate>
          </Setter.Value>
      </Setter>
  </Style>
<Page.Resource>
<Grid>
  <ListView x: Name = "InkCanvasListView" ItemContainerStyle = "{staticResource ListViewItemStyle}" BorderBrush = "{x: Null}" Background = "Transparent">
      <ListBoxItem />
      <ListBoxItem />
      <ListBoxItem />
  </ListView>
</Grid>
  • Answer # 1

    Isn't it like this if you do it roughly with just xaml?

    <Window
     x: Class = "Questions306348.MainWindow"
     xmlns = "http://schemas.microsoft.com/winfx/2006/xaml/presentation"
     xmlns: x = "http://schemas.microsoft.com/winfx/2006/xaml"
     Height = "450"
     SizeToContent = "Width">
    <Window.Resources>
    <Style x: Key = "ListViewItemStyle" TargetType = "{x: Type ListViewItem}">
     <Setter Property = "Template">
      <Setter.Value>
       <ControlTemplate TargetType = "{x: Type ListViewItem}">
        <DockPanel Width = "1480">
         <InkCanvas
            x: Name = "InputCanvas1"
            Width = "240"
            Height = "130"
            VerticalAlignment = "Bottom"
            Background = "White"
            EditingMode = "{TemplateBinding Tag}" />
         <InkCanvas
            x: Name = "InputCanvas2"
            Height = "130"
            VerticalAlignment = "Bottom"
            Background = "{x: Null}"
            EditingMode = "{TemplateBinding Tag}" />
        </DockPanel>
       </ControlTemplate>
      </Setter.Value>
     </Setter>
    </Style>
    </Window.Resources>
    <DockPanel>
      
       
      <ItemsPanelTemplate>
       <StackPanel Orientation = "Horizontal" />
      </ItemsPanelTemplate>
     </ListBox.ItemsPanel>
       
      <Style TargetType = "{x: Type ListBoxItem}">
       <Setter Property = "Template">
        <Setter.Value>
         <ControlTemplate>
          <RadioButton
             Content = "{TemplateBinding ContentPresenter.Content}"
             IsChecked = "{Binding IsSelected, RelativeSource = {RelativeSource TemplatedParent}, Mode = TwoWay}"
             Style = "{StaticResource {x: Type ToggleButton}}" />
         </ControlTemplate>
        </Setter.Value>
       </Setter>
      </Style>
     </ListBox.ItemContainerStyle>
     <InkCanvasEditingMode>Ink</InkCanvasEditingMode>
     <InkCanvasEditingMode>EraseByPoint</InkCanvasEditingMode>
     <InkCanvasEditingMode>EraseByStroke</InkCanvasEditingMode>
     <InkCanvasEditingMode>Select</InkCanvasEditingMode>
     <InkCanvasEditingMode>None</InkCanvasEditingMode>
    </ListBox>
      
       
       
       
    </ListView>
    </DockPanel>
    </Window>

    ListViewofItemsSourceIf something is bound toInkCanvasEditingModeIt's easy to change all at once (although it's a little wasteful).