我有一個包含Image
,Label
(與XAML
設計)一類PC
,我想獲得電腦列表中ListBox
其他類。使用XAML添加自定義類的ListBox中的C#WPF
我想這一點,但我得到的錯誤System.Windows.Markup.XamlParseException
:
pc p = new pc();
list_pc.Items.Add(p);
(where list_pc is a ListBox)
這是XAML
單個PC
:
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
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" mc:Ignorable="d"
x:Class="TnCyberCafe.pc"
Title="pc"
SizeToContent="WidthAndHeight"
ShowInTaskbar="False"
WindowStartupLocation="CenterScreen"
WindowStyle="None"
AllowsTransparency="True"
Background="Transparent" Width="95" Height="104.982">
<Grid HorizontalAlignment="Left" Margin="0,10,-15,10" Width="110">
<Image x:Name="image" HorizontalAlignment="Left" Height="96" VerticalAlignment="Top" Width="100" Source="Resources/aaa.png" RenderTransformOrigin="0.5,0.26" Margin="0,-16,0,0"/>
<Label Content="Label" HorizontalAlignment="Left" Height="25" Margin="20,70,0,-10" VerticalAlignment="Top" Width="45"/>
</Grid>
</Window>
這是XAML
我list_pc
:
<ListBox x:Name="liste_pc" ScrollViewer.VerticalScrollBarVisibility="Disabled">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<WrapPanel IsItemsHost="True" Orientation="Horizontal"/>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
List PCs
</ListBox>
HUH的觀察集合?您是否可以編輯您的問題以包含有關錯誤發生位置以及「xaml設計」的外觀的更多上下文? –
當我嘗試將PC添加至列表框中我得到的錯誤 – user2456665
我認爲它可以與的ObservableCollection做,但我不知道如何exctly :) –
user2456665