C
C#9mo ago
Prince J

Issue with WPF

My issue here is that when i debug it my header doesn't showcase it fully and i don't know what the solution for this is
No description
No description
No description
14 Replies
canton7
canton79mo ago
There's nowhere near enough information there I'm afraid. "When I debug it" -- what do you mean by that? When you view it in the designer? When you start your application? You've only shown a very small snippet of your code. There's no context. I've also no idea why all of that stuff in in a Label, of all things
Prince J
Prince JOP9mo ago
Basically what i mean is when i start my application the header shows the 1st photo as result. The reason i showed that snippet of code is because that's where i believe something went wrong
canton7
canton79mo ago
The snippet you posted doesn't have any of the code for the images which have disappeared though... And it's fairly clear that the header text is being positioned too low, and that's causing the stuff below it to be clipped, but you haven't provided any of the code which might be controlling that positioning Please make our lives easier, and provide anything which might be relevant
Prince J
Prince JOP9mo ago
Okay so i will first start with the photo folder i utilized.
No description
Prince J
Prince JOP9mo ago
Next up the whole code snippit is this: <Grid> <Label Background="Beige" HorizontalContentAlignment="Left" VerticalContentAlignment="Center" Margin="0,10,0,597"> <Grid Width="756" Height="173"> <Grid.ColumnDefinitions> <ColumnDefinition Width="auto"/> <ColumnDefinition Width="*"/> <ColumnDefinition Width="auto"/> </Grid.ColumnDefinitions> <Image Grid.Column="0" Source="images/logo.png" Margin="0,0,99,10"/> <TextBlock Grid.Column="1" Text="Red Jordy" FontSize="36" VerticalAlignment="Center" Margin="0,0,200,0" FontFamily="Bradley Hand ITC" TextAlignment="Center"/> <Button Grid.Column="1" Content="Login" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,0,10,0" Width="57" Height="30"/> </Grid> </Label>
canton7
canton79mo ago
Can you post all of your XAML please, as $code
MODiX
MODiX9mo ago
To post C# code type the following: ```cs // code here ``` Get an example by typing $codegif in chat For longer snippets, use: https://paste.mod.gg/
Prince J
Prince JOP9mo ago
Yes i can the xaml code is in this txt
Prince J
Prince JOP9mo ago
Couldn't do an $code for sum reason
canton7
canton79mo ago
There are a lot of problems there. I'm not sure what exactly is causing your issue, but fixing these would be a good start: 1. There's no proper layout. Everything is in a Grid, in the same row/column (i.e. stacked up on top of one another), then you're using margins to make sure it doesn't overlap. Ish. Use a proper suitable Panel which will do the layout for you. In this case, putting some rows on that outermost Grid (one row for the header, one for the body, etc) would be a good start, or use a DockPanel 2. Your <Grid Width="756" Height="173"> grid has 3 cols but you're only using 2 of them: the Button and TextBox overlap in col 1 3. Your header is in a Label. Labels are used for showing text. I'm not sure what you're trying to do there, but a Label is not the right thing to use 4. That first TextBox has a weird 200px right margin, when there is nothing to the right of it 5. Your <Grid Margin="0,-84,0,84" > has a negative margin. You should never need negative margins 6. Your <Grid Width="756" Height="190" Margin="3,271,7,323" > has some massive margins, and explicit dimensions. That's normally an indicator that it should be placed in an appropriate parent Panel which lays it out properly 7. Your <Grid Width="756" Height="190" Margin="3,271,7,323" > has 3 columns, but the last image tries to go into a non-existant 4th column 8. Your <Grid VerticalAlignment="Top" Margin="5,420,0,0" > has 3 columns, but only one child, which spans the 2nd and 3rd columns 9. The StackPanels it contains all have weird margins and explicit widths. They should be sized by an appropriate parent container So, I'm not sure why exactly your layout isn't rendering properly when you debug, it might be something as trivial as the window being slightly the wrong size, and your code is too fragile to handle it. I suspect you've just used the designer to throw something together? Don't do that with XAML -- you need to learn how to properly lay things out using the Panels -- Grid, DockPanel, StackPanel, etc. If I had to fix that, I'd throw it all away and start again, using a proper layout which is built sensibly.
Prince J
Prince JOP9mo ago
For point 3 the reason i utilized label is due to the fact i wanted to make my background beige and visible which is i was adviced to do beforehand. My logic was that i first decide on the background and then the grid as usually in my coding backgrounds are usually decided at the first line of code
canton7
canton79mo ago
You can put a background on most elements. Grid can take a Background for instance A Label is for showing text in a specific way (so that it aligns with things like a TextBox, and supports access keys)
Prince J
Prince JOP9mo ago
Alright i will try to fix it, i didn't exactly use designer or atleast tried to utilize as low as possible on this one Btw thanks it worked out at the end
Want results from more Discord servers?
Add your server