Click here to Skip to main content
15,890,557 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I have 4 WPF comboBox I want to add data to the XAML i have a code but get errors.
Content is set to more then one instance. I want to set different for each combobox.
getting lost on where the grid starts. This is very new to me and trying to do what should be simple. I dont know how to wrap each or complete each combobox
full code below

Thanks



XML
<pre><Window x:Class="WPF_Shift_End_Report.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WPF_Shift_End_Report"
        mc:Ignorable="d"
        Title="Shift End Report" Height="550" Width="948" WindowStyle="None">
    <Grid>
        <Grid.ColumnDefinitions>
            <ColumnDefinition Width="44*"/>
            <ColumnDefinition Width="4*"/>
            <ColumnDefinition Width="187*"/>
        </Grid.ColumnDefinitions>
        <Grid HorizontalAlignment="Left" Height="542" VerticalAlignment="Top" Width="203" Background="#FFBBC9C6" Grid.ColumnSpan="3">
            <Button x:Name="btn_Home" Content="Home" HorizontalAlignment="Left" VerticalAlignment="Top" Width="59" Margin="50,180,0,0" Background="{x:Null}" BorderBrush="{x:Null}" Foreground="White" FontSize="16" FontWeight="Bold" RenderTransformOrigin="0.458,-0.48"/>
            <Image x:Name="Home" HorizontalAlignment="Left" Height="28" VerticalAlignment="Top" Width="32" Margin="10,177,0,0" Source="ICO/Dog House_40px.png"/>
        </Grid>
        <Grid HorizontalAlignment="Left" Height="28" Margin="65,0,0,0" VerticalAlignment="Top" Width="875" RenderTransformOrigin="-0.133,-0.811" Background="#FFBBC9C6" MouseLeftButtonDown="Grid_MouseLeftButtonDown" Grid.ColumnSpan="3"/>
        <Image x:Name="Exit" HorizontalAlignment="Left" Height="28" VerticalAlignment="Bottom" Width="25" Grid.Column="2" Margin="713,0,0,514" Source="ICO/Delete_29px.png" MouseLeftButtonDown="image_MouseLeftButtonDown" RenderTransformOrigin="1.64,0.5" OpacityMask="Black"/>
        <Image x:Name="image" HorizontalAlignment="Left" Height="100" VerticalAlignment="Top" Width="119" Source="ICO/nissan-logo.ico" Margin="8,10,0,0"/>
        <Button x:Name="btn_SSAR" Content="SSAR" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75" Margin="91,352,0,0" Background="{x:Null}" Foreground="White" FontSize="16" FontWeight="Bold" BorderBrush="{x:Null}"/>
        <Button x:Name="btn_Part_Shortage" Content="Part Shortage" HorizontalAlignment="Left" VerticalAlignment="Top" Width="132" Margin="44,225,0,0" Background="{x:Null}" Foreground="White" FontSize="16" FontWeight="Bold" BorderBrush="{x:Null}"/>
        <Button x:Name="btn_Attendance" Content="Attendance" HorizontalAlignment="Left" VerticalAlignment="Top" Width="108" Margin="58,272,0,0" Background="{x:Null}" Foreground="White" FontSize="16" FontWeight="Bold" BorderBrush="{x:Null}"/>
        <Button x:Name="btn_Hot_Calls" Content="Hot Calls" HorizontalAlignment="Left" VerticalAlignment="Top" Width="75" Margin="91,307,0,0" Background="{x:Null}" Foreground="White" FontSize="16" FontWeight="Bold" BorderBrush="{x:Null}"/>
        <Button x:Name="btn_Restriction" Content="Restriction" HorizontalAlignment="Left" VerticalAlignment="Top" Width="85" Margin="81,426,0,0" Background="{x:Null}" Foreground="White" FontSize="16" FontWeight="Bold" BorderBrush="{x:Null}"/>
        <Button x:Name="btn_open_Parts" Content="Open Parts Issue" HorizontalAlignment="Left" VerticalAlignment="Top" Width="138" Margin="44,382,0,0" Background="{x:Null}" Foreground="White" FontSize="16" FontWeight="Bold" BorderBrush="{x:Null}" Grid.ColumnSpan="2"/>
        <Image x:Name="PartShortage" HorizontalAlignment="Left" Height="25" VerticalAlignment="Top" Width="36" Margin="10,225,0,0" RenderTransformOrigin="-5.056,0.638" Source="ICO/Administrative Tools_40px.png"/>
        <Image x:Name="Restriction" HorizontalAlignment="Left" Height="25" VerticalAlignment="Top" Width="36" Margin="10,445,0,0" Source="ICO/Medical 2.jpg" RenderTransformOrigin="0.556,-0.76"/>
        <Image x:Name="Attendance" HorizontalAlignment="Left" Height="25" VerticalAlignment="Top" Width="36" Margin="10,272,0,0" RenderTransformOrigin="0.583,2.84" Source="ICO/Add User Group Man Man_40px.png"/>
        <Image x:Name="image4" HorizontalAlignment="Left" Height="25" VerticalAlignment="Top" Width="36" Margin="8,352,0,0" RenderTransformOrigin="-6.667,0.04"/>
        <Image x:Name="image5" HorizontalAlignment="Left" Height="25" VerticalAlignment="Top" Width="36" Margin="10,401,0,0" RenderTransformOrigin="0.5,1.48"/>
        <Image x:Name="HotCalls" HorizontalAlignment="Left" Height="25" VerticalAlignment="Top" Width="36" Margin="10,307,0,0" RenderTransformOrigin="-1.63,0.65" Source="ICO/White flame.png" OpacityMask="#FF891B15"/>
        <Grid HorizontalAlignment="Left" Height="77" VerticalAlignment="Top" Width="737" Grid.Column="2" Margin="11,28,0,0" Background="#FF23A2B6">
            <ComboBox x:Name="comboBox2" HorizontalAlignment="Left" VerticalAlignment="Top" Width="73" Margin="150,45,0,0"/>
            <ComboBoxItem Content="X"/>
            <ComboBoxItem Content="Y"/>
            <ComboBoxItem Content="Z"/>
                        
            <ComboBox x:Name="comboBox3" HorizontalAlignment="Left" Margin="257,45,0,0" VerticalAlignment="Top" Width="78" RenderTransformOrigin="-0.013,0.409"/>
            <ComboBoxItem Content="a"/>
            <ComboBoxItem Content="s"/>
            <ComboBoxItem Content="d"/>
                
            <ComboBox x:Name="comboBox4" HorizontalAlignment="Left" VerticalAlignment="Top" Width="79" Margin="363,45,0,0"/>
            <ComboBoxItem Content="f"/>
            <ComboBoxItem Content="g"/>
            <ComboBoxItem Content="h"/>
                    
            <ComboBox x:Name="comboBox5" HorizontalAlignment="Left" VerticalAlignment="Top" Width="120" Margin="486,45,0,0"/>
            <ComboBoxItem Content="j"/>
            <ComboBoxItem Content="k"/>
            <ComboBoxItem Content="l"/>
                        <ComboBox>
            <ComboBox x:Name="comboBox6" HorizontalAlignment="Left" VerticalAlignment="Top" Width="86" Margin="632,45,0,0" RenderTransformOrigin="0.802,0.545"/>
           
        </Grid>
        <DatePicker HorizontalAlignment="Left" VerticalAlignment="Top" Grid.Column="2" Margin="31,68,0,0"/>

    </Grid>
</Window>


What I have tried:

can not find an example of comboboxs together in a group.
Posted
Updated 17-Jan-18 10:42am
v3
Comments
Graeme_Grant 17-Jan-18 3:15am    
Why do you want all 5 ComboBoxes with the same content? Why do you want to hard-code the ComboBox content in Xaml?

1 solution

When you get that error it means you have the Content set both as an attribute and in the body of the XAML.

The XAML you have is incomplete so I can't say 100% where it is. As an example, this will cause an error:
<ComboBoxItem Content="d">e</ComboBoxItem>

In this case you're trying to set Content in two places "d" and "e" so you get the error.
 
Share this answer
 

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