English 中文(简体)
包装件清单
原标题:Binding Items to Listbox

我在一份申请书中向用户展示了某一字的含义。 因此,我在前面使用一个名单Box。 这里是法典。

XAML:

<ListBox Background="White" Grid.Row="1" ItemsSource="{Binding}" Height="605" HorizontalAlignment="Stretch" Margin="0,90,0,0" Name="listBox1" VerticalAlignment="Top">
  <ListBox.ItemTemplate>
    <DataTemplate>
      <StackPanel Orientation="Vertical" Height="50">
        <TextBlock Text="{Binding ActualWord}" Height="5" />
        <TextBlock Text="{Binding Meaning}"  Height="5"/>
        <TextBlock Text="{Binding Type}" Height="5"/>
        <TextBlock Text="{Binding Example}" Height="5" />
      </StackPanel>
    </DataTemplate>
  </ListBox.ItemTemplate>
</ListBox>

C# 添加背后的措辞。

listBox1.Items.Add(new WordClass()
{
    ActualWord = "Something",
    Type = "Something111",
    Meaning =  "Something222",
    Example =  "Something333"
});

问题是,该守则汇编了,但我看着一个空白的屏幕,或换言之,在名单箱中没有任何东西,即使我是在页台上这样做的。

问题回答

删除<代码>ItemsSource=”{Bled}> part from You XAML. 由于你手工填写清单,你不需要填写清单,这可能造成问题。

另一种选择是将你的XAML留给它,以填写<代码>WordClass,并将其定为<代码>DataContext:

var list = new List<WordClass>();
list.Add(new WordClass()
{
    ActualWord = "Something",
    Type = "Something111",
    Meaning =  "Something222",
    Example =  "Something333"
});
...

this.DataContext = list;




相关问题
Anyone feel like passing it forward?

I m the only developer in my company, and am getting along well as an autodidact, but I know I m missing out on the education one gets from working with and having code reviewed by more senior devs. ...

NSArray s, Primitive types and Boxing Oh My!

I m pretty new to the Objective-C world and I have a long history with .net/C# so naturally I m inclined to use my C# wits. Now here s the question: I feel really inclined to create some type of ...

C# Marshal / Pinvoke CBitmap?

I cannot figure out how to marshal a C++ CBitmap to a C# Bitmap or Image class. My import looks like this: [DllImport(@"test.dll", CharSet = CharSet.Unicode)] public static extern IntPtr ...

How to Use Ghostscript DLL to convert PDF to PDF/A

How to user GhostScript DLL to convert PDF to PDF/A. I know I kind of have to call the exported function of gsdll32.dll whose name is gsapi_init_with_args, but how do i pass the right arguments? BTW, ...

Linqy no matchy

Maybe it s something I m doing wrong. I m just learning Linq because I m bored. And so far so good. I made a little program and it basically just outputs all matches (foreach) into a label control. ...

热门标签