Click here to Skip to main content
14,921,505 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi! I'm quite new to WPF and I'm trying to create a Listview with items that consists of a checkbox with label and a textbox next to the Checkbox. The XAML markup looks like this:
XML
<ListView ItemsSource="{Binding PricingList}" Margin="0,49,0,238" SelectionMode="Extended" x:Name="lvItems">
    <ListView.ItemTemplate>
        <DataTemplate>
            <Grid>
                <CheckBox IsChecked="{Binding IsChecked}" Content="{Binding Path=Item.Display}" Checked="CheckBox_Checked" Unchecked="CheckBox_Checked">
                </CheckBox>
                <TextBox Text="{Binding Path=Item.Menge}"  Margin="10,10,0,0">
                </TextBox>
            </Grid>
        </DataTemplate>
    </ListView.ItemTemplate>
</ListView>

The databinding works very well. Problem is the items are looking very weird. I believe the markup is rather catastrophic. I hope anyone an help me...
Posted
Comments
Gokulprasad05 3-Feb-16 4:57am
   
How did you expect ur output show in image
susad 3-Feb-16 5:13am
   
this is how it should look like: http://www.directupload.net/file/d/4253/erwpb52l_png.htm

And this is how it actually looks: http://www.directupload.net/file/d/4253/n7l884e9_png.htm

1 solution

XML
<ListViewItem ItemsSource="{Binding PricingList}" Margin="0,49,0,238" SelectionMode="Extended" x:Name="lvItems">               

        <CheckBox IsChecked="{Binding IsChecked}" Content="{Binding Path=Item.Display}" Checked="CheckBox_Checked" Unchecked="CheckBox_Checked">

            <StackPanel Orientation="Horizontal">

            <TextBlock Text="{Binding Path=Item.Menge}" Margin="10,10,0,0"></TextBlock>

        </StackPanel>

    </CheckBox>

</ListViewItem>
   
Comments
susad 3-Feb-16 5:51am
   
YES! Thank You! This looks way better. I had to remove the CheckBox.Content-attribute and inserted a Label before the Textbox to show the Item.Display-value.
Gokulprasad05 3-Feb-16 5:59am
   
<Label Name="MyLabel" FontSize="17pt" HorizontalContentAlignment="Center" Margin="10,10,10,0" VerticalAlignment="Top" Height="40"
Content="{Binding Path=Item.Display, UpdateSourceTrigger=PropertyChanged}"/>


<stackpanel orientation="Horizontal">

<textblock text="{Binding Path=Item.Menge}" margin="10,10,0,0">





</ListViewItem>

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900