control not positioning right - wpf

I wantto postion control like this pic
I need Next and previous buttons to be as pic 1, but i get the following, and not able to solve this.
Please guide, XAML code:
<StackPanel Grid.Row="4">
<Grid x:Name="GridNavigation">
<Button x:Name="Gridprevbutton" Content="Previous" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="121,0,0,0"></Button>
<Button x:Name="Gridnextbutton" Content="Next" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="231 , 0, 0, 0"></Button>
<Button x:Name="Gridendexambuton" Content="End Exam" VerticalAlignment="Top" HorizontalAlignment="Right" Margin="0,0,5,0"></Button>
</Grid>
<TextBlock HorizontalAlignment="Right" Margin="0,5,10,0" TextDecorations="Underline">Contact Support</TextBlock>
</StackPanel>
(Edit) I end up doing this following #davisoa advise. and got it working.
Code behind
private void SetNavigation()
{
var img = Common.AddImageToContainer("images/lowerleftblock.png", GridNavigation, Common.ToDictionaryTLST("top", "left", "none"));
img.Margin = new Thickness(0,16,0,0);
Panel.SetZIndex(img, -1);
}

Give your image a top margin to bring it down by however much is needed.
E.g.
<Image x:Name="Lowerleftblock" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="0,20,0,0"></Image>

It looks to me like the Grid you are not showing above (the first StackPanel is in Grid.Row="4") is limiting the height of your Next and Previous buttons.
This example XAML shows the Question block lower than the buttons.
Changed Image to a StackPanel with a Label, since I don't have your image
Changed VerticalAlignment to Bottom, to ensure it floats on the bottom of the Grid
Gave the Grid a fixed Height to ensure the vertical layout is correct. You probably don't want to do this
<StackPanel Grid.Row="4">
<Grid x:Name="GridNavigation" Margin="0,0,0,0" Height="75">
<StackPanel x:Name="Lowerleftblock" VerticalAlignment="Bottom" HorizontalAlignment="Left" Margin="0,0,0,0" Background="Green">
<Label>Question: 1 of 27</Label>
</StackPanel>
<Button x:Name="Gridprevbutton" Content="Previous" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="121,0,0,0"></Button>
<Button x:Name="Gridnextbutton" Content="Next" VerticalAlignment="Top" HorizontalAlignment="Left" Margin="231 , 0, 0, 0"></Button>
<Button x:Name="Gridendexambuton" Content="End Exam" VerticalAlignment="Top" HorizontalAlignment="Right" Margin="0,0,5,0"></Button>
</Grid>
<TextBlock HorizontalAlignment="Right" Margin="0,5,10,0" TextDecorations="Underline">Contact Support</TextBlock>
</StackPanel>

Related

WPF Dockpanel won't align right

I have this code on which I use a DockPanel on a Button.Content. However it doesn't let me right align the last image (small arrow).
<Button Height="70"
HorizontalContentAlignment="Left">
<Button.Content>
<DockPanel LastChildFill="False">
<Image DockPanel.Dock="Left"
Height="50"
Width="50"
Source="{StaticResource Placeholder}"
Stretch="UniformToFill"
Margin="5" />
<TextBlock DockPanel.Dock="Left"
Text="Dummy text"
VerticalAlignment="Center"
Margin="5" />
<Image DockPanel.Dock="Right"
Height="24"
Width="24"
Source="{StaticResource Right_Arrow_24}"
VerticalAlignment="Center"
HorizontalAlignment="Right"
Stretch="UniformToFill"
Margin="5" />
</DockPanel>
</Button.Content>
</Button>
It now gives me this:
So the right small arrow should be placed on the right of the button and not just after the TextBlock.
I've found some similar issues and it looks like I did it correct, but somehow it isn't..
What am I doing wrong here?
Try to set the HorizontalContentAlignment of your button to "Stretch". Otherwise your DockPanel will use the size need by its content, then align left. You can confirm this behaviour by using different text lengths for your TextBlocks
You simply have to append an extra child to the DockPanel (say an empty Canvas) without the DockPanel.Dock attribute, so that all the remaining space is assigned to it.
In general, DockPanel only works fine only when its last child has no Dock constraint
Try setting
HorizontalContentAlignment="Stretch"
On your button.

Calendar control width is too large at initialization of usercontrol

I have used calendar control and its display mode is year when my user control is loads then calender width s too large and doesn't appear when width is set .but when is select any month then width is set as it should
i m not getting what is the issue behind it
can anyone help me quickly???
Here is my code and what ever selected month will appear in textbox's text property and on click event of button my calendar control is set to visible
<StackPanel Grid.Row="0" Grid.Column="0" Orientation="HorizontalHorizontalAlignment="Left "Margin="4">
<Label Content="Month: " HorizontalAlignment="Right" VerticalAlignment="Top" FontSize="15" FontWeight="DemiBold" Margin="4"/>
<TextBox Height="23" HorizontalAlignment="Stretch" Name="SelectedMonthTextBox" VerticalAlignment="Top" Width="130" Margin="4" LostFocus="SelectedMonthTextBox_LostFocus" SelectionBrush="#FF767879"/>
<Button Content=".." Height="20" Width="20" Margin="4" Name="button" Click="button_Click" />
</StackPanel>
<Calendar Grid.Row="1" Grid.Column="0" Margin="50,-8" Panel.ZIndex="100" Name="calendar1" DisplayModeChanged="calendar1_DisplayModeChanged" DisplayDateChanged="calendar1_DisplayDateChanged" HorizontalAlignment="Left" DisplayMode="Year" Style="{StaticResource CalendarStyle}" Focusable="False" HorizontalContentAlignment="Left" VerticalAlignment="Top" />
i took a look your code and from information you provided so far, there is no any change a you describe. I believe that you should check following:
What happens in calendar1_DisplayModeChanged
How defined your style: StaticResource CalendarStyle
If it possible please post them here. I will try to help as soon as possible :)

ListBox with "load more" option

I would like to know how to construct the ListBox in WP7 that only load 20 items at a single time, and have a footer that show "load more" if there is any.
When user press the "load more", it will load another 20 in the list without loading the previous loaded data?
I am using LINQ at the behind source.
my code for XMAL as follow:
<Grid>
<ListBox name="newsIndexListBoxEN">
<ListBoxItem>
<DataTemplate>
<StackPanel Width="410" Orientation="Horizontal" VerticalAlignment="Top" Margin="0,5,0,5">
<StackPanel Background="DarkBlue" Margin="10,0,0,0" Height="100" Width="100" VerticalAlignment="Top">
<TextBlock Name="columnsTypeTB" Text="{Binding pType}" Margin="0,0,0,0" Foreground="White" FontSize="23" HorizontalAlignment="Center" />
<Image Width="100" Height="100" VerticalAlignment="Top" HorizontalAlignment="Center" Source="Background.png" />
</StackPanel>
<StackPanel Width="300" Height="100" Margin="0,0,0,0">
<Path Margin="0,0,0,0" Data="M39,8 L389,8" Fill="DarkBlue" Height="1" Stretch="Fill" Stroke="DarkBlue" UseLayoutRounding="False" Width="400"/>
<TextBlock Margin="8,0,0,0" Text="{Binding pTitle}" Tag="{Binding pID}" Style="{StaticResource PhoneTextNormalStyle}" TextWrapping="Wrap" Width="292" Height="66" />
<TextBlock Margin="8,5,0,0" Text="{Binding pDate}" Tag="{Binding pID}" MouseEnter="NewsViewContent_mouseEnter" Style="{StaticResource PhoneTextSmallStyle}" VerticalAlignment="Bottom" TextWrapping="Wrap" Width="292" />
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBoxItem>
</ListBox>
</Grid>
C# Code as follow:
using (IsolatedStorageFile storage = IsolatedStorageFile.GetUserStoreForApplication())
{
using (IsolatedStorageFileStream fs = storage.OpenFile(fileName, FileMode.Open))
{
XDocument menuIndex = XDocument.Load(fs);
var menuIndexList = from query in menuIndex.Descendants("news")
orderby (int)query.Element("newsID") descending
select new mkmenu
{
pID = query.Element("newsID").Value,
pTitle = query.Element("newsTitle").Value,
pDate = query.Element("newspDate").Value,
pType = newsType
};
newsIndexListBoxEN = menuIndexList.Count();
}
}
any ideas? sample code?
You can edit your listbox template to show a "Load more" button at the end of the list. In Blend, right click on your listbox, choose Edit Template, Edit a copy. By default, your listbox has a template like this:
ScrollViewer
ItemPresenter
Wrap your ItemPresenter into a StackPanel, then add a button at the end:
ScrollViewer
StackPanel
ItemPresenter
Button
That button will always be displayed at the end of the listbox. Handle the Clicked event of that button to add items to your ObservableCollection.
You can bind your listbox to ObservableCollection and add first 20 items on your page(app) load. Than after pressing "load more" get next 20 items and add to collection. Items will automatically be added to listbox.

WPF textblock cuts off multiple lines on windows 7

I am using a textblock to display the product description under the product's image. The text must be fixed 100px wide but the height can grow up to 30px tall. If the text still can't fit, it must display ellipsis. Here is my xaml:
<StackPanel>
<!-- I use canvas here to reserve some space for animation (grow/shrink) -->
<Canvas Height="75" Width="75">
<Image x:Name="picture" Height="64" Width="64" .../>
<Canvas/>
<TextBlock Width="100" MaxHeight="30"
TextTrimming="CharacterEllipsis" TextWrapping="Wrap"
Text="{Binding Path=ProductDescription}"
HorizontalAlignment="Center" VerticalAlignment="Top" TextAlignment="Center">
</StackPanel>
The description can have multiple lines. For eg, "Wireless Mouse\nQuantity:20". It looks ok on XP but on Windows 7 only the first line shows up and there's no ellipsis. Can anyone spot the problem in my xaml?
There are several errors in your example: should , ".../>" isn't valid XAML and your TextBlock doesn't have a closing tag.
The follow XAML worked fine on for me on Windows 7:
<StackPanel>
<!-- I use canvas here to reserve some space for animation (grow/shrink) -->
<Canvas Height="75" Width="75">
<Image x:Name="picture" Height="64" Width="64" />
</Canvas>
<TextBlock Width="100" MaxHeight="30"
TextTrimming="CharacterEllipsis" TextWrapping="Wrap"
Text="I use canvas here to reserve some space for animation (grow/shrink)"
HorizontalAlignment="Center"
VerticalAlignment="Top"
TextAlignment="Center" />
</StackPanel>
Depending on the font size MaxHeight of 30 is almost just one line of text, so the textblock can't grow in height. Change it or remove it completely.

Change content of ImageButton programatically (WPF)

I am using a ImageButton as
<Button Width="80" Height="25"
VerticalAlignment="Top"
HorizontalAlignment="Right"
HorizontalContentAlignment="Center"
VerticalContentAlignment="Center"
Margin="0,0,1.5,0"
Name="btnActivate"
Click="OnActivate">
<StackPanel Orientation="Horizontal" Margin="3">
<Image Source="Shutdown.ico"
Width="12" Height="12"
Margin="0,0,5,0"/>
<TextBlock>Activate</TextBlock>
</StackPanel>
</Button>
I want to change the Content of button to 'Deactivate' when I click on it without changing the image. How can I do that? And also I need to some operations based on the content of button in my C# code.
You could just add a name to the TextBlock
<TextBlock Name="textBlock1">Activate</TextBlock>
and use it to modify the content in your OnActivate event handler
textBlock1.Text = "Deactivate";

Resources