This is a migrated thread and some comments may be shown as answers.

ListBox or GridView Bind Custom Shape's ViewModel Data in the SettingsPaneView

1 Answer 194 Views
Diagram
This is a migrated thread and some comments may be shown as answers.
Li
Top achievements
Rank 1
Li asked on 19 Aug 2020, 03:46 AM

Hi,I'm Using Custom Shape  and I want to Add a ListBox to the SettingsPaneView and Bind the shape's ViewModel to the Listbox ,but the data now show ,Anybody can help me,Thanks.

 

private List<AdjacentSpace6VM> _AdjacentSpaces;
 
    public List<AdjacentSpace6VM> AdjacentSpaces
    {
        get
        {
            return _AdjacentSpaces;
        }
        set
        {
            _AdjacentSpaces = value;
            OnPropertyChanged(() => this.AdjacentSpaces);
        }
    }
<ListBox extensions:SettingsPaneView.EditorPropertyName="DataContext.AdjacentSpaces" extensions:SettingsPaneView.EditorItemType="Shapes,Custom, Connections" extensions:SettingsPaneView.EditorValue="{Binding Path=ItemsSource, Mode=TwoWay, RelativeSource={RelativeSource Self}}" Grid.Row="3" Grid.ColumnSpan="2">
                      <ListBox.ItemsPanel>
                          <ItemsPanelTemplate>
                              <UniformGrid Columns="3" IsItemsHost="True" Margin="0" />
                          </ItemsPanelTemplate>
                      </ListBox.ItemsPanel>
                      <ListBox.ItemContainerStyle>
                          <Style TargetType="{x:Type ListBoxItem}">
                              <Setter Property="Template">
                                  <Setter.Value>
                                      <ControlTemplate TargetType="{x:Type ListBoxItem}">
                                          <Grid>
                                              <Grid.ColumnDefinitions>
                                                  <ColumnDefinition></ColumnDefinition>
                                                  <ColumnDefinition></ColumnDefinition>
                                              </Grid.ColumnDefinitions>
                                              <TextBlock Grid.Column="0" Text="{Binding Number}" VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="30" Margin="30 10 0 20" Foreground="White"></TextBlock>
                                              <TextBlock Grid.Column="1" Text="{Binding CT}" VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="30" Margin="10 10 30 20" Foreground="White"></TextBlock>
                                              <TextBlock Grid.Column="1" Text="aaa" VerticalAlignment="Center" HorizontalAlignment="Center" FontSize="30" Margin="10 10 30 20" Foreground="White"></TextBlock>
                                          </Grid>
                                      </ControlTemplate>
                                  </Setter.Value>
                              </Setter>
                          </Style>
                      </ListBox.ItemContainerStyle>
                  </ListBox>

1 Answer, 1 is accepted

Sort by
0
Vladimir Stoyanov
Telerik team
answered on 21 Aug 2020, 09:21 AM

Hello Li,

Thank you for the shared code snippet.

You can check out the CustomSettingsPane SDK example in order to see how to customize the settings pane. 

That said, you don't have to use the SettingsPaneView properties in order to bind to a collection in your viewmodel. I am attaching the above mentioned SDK example updated to demonstrate how you can do that by binding the ItemsSource of the ListBox element directly. 

I hope you find this helpful.

Regards,
Vladimir Stoyanov
Progress Telerik

Five days of Blazor, Angular, React, and Xamarin experts live-coding on twitch.tv/CodeItLive , special prizes and more, for FREE?! Register now for DevReach 2.0(20).

Tags
Diagram
Asked by
Li
Top achievements
Rank 1
Answers by
Vladimir Stoyanov
Telerik team
Share this question
or