簡體   English   中英

動態將項目添加到網格WPF

[英]Dynamically add items to grid WPF

我有以下“網格”:

<Grid x:Name="ImagesGrid" Grid.Row="1"  >
    <ItemsControl ItemsSource="{Binding FrameViewers}" />
</Grid>

我還具有以下UserControl項目集合:

private ObservableCollection<FrameViewer> m_frameViewers = new ObservableCollection<FrameViewer>();

public ObservableCollection<FrameViewer> FrameViewers
{
    get => m_frameViewers;
    set
    {
        m_frameViewers = value;
        OnPropertyChanged();
    }
}

我想動態地將FrameViewer添加到我的屏幕,使其看起來像所附的圖像: 在此處輸入圖片說明

目前,我看到它們像這樣垂直排列: 在此處輸入圖片說明

我能夠使用“網格”,並在ItemSource添加了一個StackPanel ,但是它們都按照標題的長度進行了大小調整,並附加在Grid的左側

我在這里想念什么? 我想念什么?

默認情況下,ItemsControl將垂直排列項目。

對於水平布局,你需要改變它的ItemsPanel ,到不同的ItemsPanelTemplate -使用一個水平的StackPanel,或像一個UniformGrid,這取決於你想要的時候有集合中三個以上FrameViewer項目發生什么。

請參閱此處的一些示例。

然后,您需要將ItemsControl ItemTemplate設置為適當的DataTemplate ,以確保以所需的大小顯示每個FrameViewer項。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM