可以在Stackpanel中查看整个对象吗?

发布于 2025-02-06 11:46:02 字数 1516 浏览 2 评论 0原文

我是WPF中的新手,试图创建他的第一个正常项目,即注释申请。 每个音符都链接到按钮,我认为它在stackpanel中看起来很漂亮。 我正在在stackpanel中动态创建按钮 s,但是问题是当我向下滚动button s last button的列表时/代码>无法完全看到。我以为是因为保证金并试图对其进行调整,但没有帮助,auto height and width无济于事。 stackpanelscrollviewer中,当我到达scrollbar的结尾时,我只能看到最后一个按钮的一半?

这是stackpanel's xaml代码:

    <ScrollViewer VerticalScrollBarVisibility="Auto" 
    Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="3" Grid.RowSpan="3" Margin="50 -50 50 5" >
                <StackPanel x:Name="ButtonPanel"/>
    </ScrollViewer>

这就是我创建button

            dynamicTextBox.Add(SearchNotes); 
            dynamicTextBox[index_of_buttons] = new TextBox();
            Grid.SetRow(dynamicTextBox[index_of_buttons], 1);
            Grid.SetColumn(dynamicTextBox[index_of_buttons], 0);
            this.ButtonPanel.Children.Add(dynamicTextBox[index_of_buttons]);
            dynamicTextBox[index_of_buttons].IsReadOnly = false;
            dynamicTextBox[index_of_buttons].Text = "";

where dynamictextbox is code> list&lt;&gt; textbox es应用模板(我认为没有必要查看模板解决问题)

这就是外观: 看不到整个按钮(最后一个)

所以我想看看整个按钮。

I am a newbie in WPF trying to create his first normal project which is a notes application.
Every note is linked to a button and I thought it'll look beautiful in StackPanel.
I am dynamically creating buttons within StackPanel, but the problem is that when I scroll down the list of Buttons last Button can't be seen fully. I thought it was because of the Margin and tried to adjust it, but it didn't help, also auto Height and Width didn't help. StackPanel is within ScrollViewer and when I reach the end of ScrollBar I just can see half of last button ?

Here is StackPanel's XAML code:

    <ScrollViewer VerticalScrollBarVisibility="Auto" 
    Grid.Row="1" Grid.Column="0" Grid.ColumnSpan="3" Grid.RowSpan="3" Margin="50 -50 50 5" >
                <StackPanel x:Name="ButtonPanel"/>
    </ScrollViewer>

That is how I create Button:

            dynamicTextBox.Add(SearchNotes); 
            dynamicTextBox[index_of_buttons] = new TextBox();
            Grid.SetRow(dynamicTextBox[index_of_buttons], 1);
            Grid.SetColumn(dynamicTextBox[index_of_buttons], 0);
            this.ButtonPanel.Children.Add(dynamicTextBox[index_of_buttons]);
            dynamicTextBox[index_of_buttons].IsReadOnly = false;
            dynamicTextBox[index_of_buttons].Text = "";

Where dynamicTextBox is List<> of TextBoxes to which is applied Template(I think it is not necessary to see Template to resolve the problem)

This is how it looks like:
Can't see the whole button(the last one)

So I wanna see the whole button.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

泼猴你往哪里跑 2025-02-13 11:46:02

正如Andy在评论部分中所写的那样,ListBox是解决此问题的最佳解决方案。
我尝试了这个使它看起来与Stackpanel

Xaml中完全相同:

<ListBox Name="ListBoxOfButtons" Background="#404040" BorderThickness="0" 
                 HorizontalContentAlignment="Stretch" Grid.Row="1" Grid.Column="0" 
                 Grid.ColumnSpan="3" Grid.RowSpan="3" Margin="50 -20 50 5">
</ListBox>

c#:

var txtBox = new TextBox();
txtBox.Template = FindResource("TemplateForTextBox") as ControlTemplate;
ListBoxOfButtons.Items.Add(txtBox);

这是最后的最后按钮看起来像现在

As Andy wrote in the comment section, ListBox is best solution for this problem.
I tried this one to make it look like exactly same as it was in StackPanel

Xaml:

<ListBox Name="ListBoxOfButtons" Background="#404040" BorderThickness="0" 
                 HorizontalContentAlignment="Stretch" Grid.Row="1" Grid.Column="0" 
                 Grid.ColumnSpan="3" Grid.RowSpan="3" Margin="50 -20 50 5">
</ListBox>

C#:

var txtBox = new TextBox();
txtBox.Template = FindResource("TemplateForTextBox") as ControlTemplate;
ListBoxOfButtons.Items.Add(txtBox);

This is how last button looks like now

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文