C#Canvas List / Array [英] C# Canvas List/Array

查看:57
本文介绍了C#Canvas List / Array的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

好吧,我遇到了一些C#设计问题,我开始疯狂地想着想法,所以我发帖要求一些帮助。



我试图创建一个动态创建的Canvas框列表,并将其放入可以滚动的列表中,它们都包含相同的按钮/标签,但每个都有不同的信息。我希望它像ListBox一样。我可以使用ListBox / ListView来创建我想要实现的东西,但它看起来并不像这样。我真的不确定该去哪里。我读过我可以动态创建一个画布项并将其添加到WrapPanel但我真的不确定。我很难解释我想要做什么,所以我为此做了道歉。我附上了一张图片,告诉你我想要达到的目的:



http://i.imgur.com/VnAOmsI.png



提前致谢:)



编辑:我正在使用WPF窗口

Gooday , I am having some C# Design trouble and I am starting to go insane trying to think of ideas so I am posting to ask for a bit of help.

I am trying to create a list of Canvas boxes that are dynamically created and put into a list that you can scroll through, they all contain the same buttons/labels ect but each with different information. I would like it to act like a ListBox. I could just use a ListBox / ListView to create what I am trying to achieve but it doesnt look as good as this. I am really unsure on where to go with this. I read I could dynamically create a canvas item and add it to a WrapPanel but I am really not sure. Its very hard to explain what I am trying to do so I do appologise for that. I have attached an image which should show you what I am trying to achieve:

http://i.imgur.com/VnAOmsI.png

Thanks in advance :)

I am using a WPF Window

推荐答案

我设法通过添加一个ListBox并以我想要的样式创建一个模板来解决我的问题。



然后我只是添加到你可以正常做的列表框。



XAML:



I managed to solve my problem by adding a ListBox and creating a Template in the style I want for it.

I then simply added to the Listbox as you would do normally.

XAML:

<ListBox x:Name="LstEvents" HorizontalAlignment="Left" Height="343" Margin="10,228,0,0" VerticalAlignment="Top" Width="524" BorderBrush="Black">
            <ListBox.Background>
                <SolidColorBrush Color="{DynamicResource WhiteColor}"/>
            </ListBox.Background>
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <Grid>
                        <Canvas x:Name="EventItem_Copy1" HorizontalAlignment="Left" Height="76" VerticalAlignment="Top" Width="502" Background="#99E8E8E8">
                            <Label Content="Event:" HorizontalAlignment="Left" Height="33" VerticalAlignment="Top" Width="97" FontWeight="Bold" FontSize="14" Canvas.Left="1" Canvas.Top="2"/>
                            <Label Content="Subject:" HorizontalAlignment="Left" Height="33" VerticalAlignment="Top" Width="97" FontWeight="Bold" FontSize="14" Canvas.Left="1" Canvas.Top="26"/>
                            <Label Content="Body:" HorizontalAlignment="Left" Height="33" VerticalAlignment="Top" Width="97" FontWeight="Bold" FontSize="14" Canvas.Left="1" Canvas.Top="49"/>
                            <Button Content="Select" HorizontalAlignment="Left" Height="33" VerticalAlignment="Top" Width="74" Background="#FF333333" Foreground="White" FontWeight="Normal" FontSize="14" Canvas.Left="418" Canvas.Top="24"/>
                            <Label Content="{Binding Path=Levent}" Height="25" Canvas.Left="71" Canvas.Top="4" Width="107"/>
                            <Label Content="{Binding Path=Lsubject}" Height="25" Canvas.Left="71" Canvas.Top="28" Width="107"/>
                            <Label Content="{Binding Path=Lbody}" Height="25" Canvas.Left="71" Canvas.Top="53" Width="107"/>
                        </Canvas>
                    </Grid>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>







等级:






Class:

public void Button_Click_2(object sender, RoutedEventArgs e)
{

    var x = new
    {
        Levent = "EventText", //These will become variables
        Lsubject = "SubjectText",
        Lbody = "BodyText"
    };

    LstEvents.Items.Add(x);

}


这篇关于C#Canvas List / Array的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆