我可以通过代码而不是 xaml 编辑 ListBox 容器样式吗?
因为:
我有自己的 ListBox 项目,我正在这样做:
Expander.Expander a = new Expander.Expander();
                    a.IsExpanded = false;
                    TestItem TI = new TestItem();
                    TI.Tap += (s, e) =>
                    {
                        NavigationService.Navigate(new Uri((App.Current as App).Course, UriKind.Relative));
                    };
                    TI.Tag = "/CourseInfoPage.xaml";
                    ListBox list = new ListBox();
                    list.Items.Add(TI);
                    list.Height = 200;
                    a.Content = list;
                    a.HeaderContent = Semestris.Name;
                    Stack.Children.Add(a);
我需要在 ListBox 的整个宽度上拉伸的项目。在我的程序中之前,我使用了这个 xaml:
<Style x:Key="ListBoxItemStyle" TargetType="ListBoxItem">
        <Setter Property="HorizontalContentAlignment" Value="Stretch" />
    </Style>
但现在我只有 C# 和原生 ListBox