我是 WPF 的新手,試圖創建他的第一個普通專案,即筆記應用程式。每個音符都鏈接到一個button,我認為它看起來很漂亮StackPanel。我在buttons 內動態創建StackPanel,但問題是當我向下滾動Buttons last的串列時Button無法完全看到。我以為是因為,Margin并試圖調整它,但它沒有幫助,也auto Height沒有Width幫助。StackPanel在里面ScrollViewer,當我走到盡頭時,ScrollBar我只能看到最后一個按鈕的一半?
這是StackPanelXAML 代碼:
<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 = "";
es在哪里dynamicTextBox應用List<> 了 TextBoxTemplate(我覺得沒必要看Template來解決問題)
這是它的樣子: 看不到整個按鈕(最后一個)
所以我想看看整個按鈕。
uj5u.com熱心網友回復:
正如安迪在評論部分所寫,ListBox是解決這個問題的最佳方案。我試過這個讓它看起來和 StackPanel 中的完全一樣
xml:
<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);
這是最后一個按鈕現在的樣子
轉載請註明出處,本文鏈接:https://www.uj5u.com/yidong/492872.html
上一篇:按鈕上的C#WPF影像被切斷
