Am requesting for help on how i can dynamically change the value of the ImageSource for the ImageBrush contained in the DataTemplate.
Below is my XAML Code :
<StackPanel Grid.Row="0" Grid.Column="0" Grid.ColumnSpan="2" Orientation="Horizontal">
<TextBlock Text="{x:Bind first_name}"
Name="TxtFirstName"
Margin="10,0,0,0"
FontSize="18" FontWeight="Bold" FontStyle="Italic"/>
<TextBlock Text="{x:Bind last_name}"
Name="TxtLastName"
Margin="10,0,0,0"
FontSize="18" FontWeight="Bold" FontStyle="Italic"/>
</StackPanel>
<StackPanel Grid.Row="1" Grid.Column="1" Margin="0,40,0,0" HorizontalAlignment="Left" >
<Ellipse Width="200" Height="200" Name="ProfilePicEllipse">
<Ellipse.Fill>
<ImageBrush x:Name="ProfilePic"
ImageSource="{x:Bind image_url}" />
</Ellipse.Fill>
</Ellipse>
<Image x:Name="ResultImage" Stretch="UniformToFill"/>
</StackPanel>
<StackPanel Grid.Row="1" Grid.Column="1" Margin="0,40,0,0">
<TextBlock Text= "{x:Bind profile}"
VerticalAlignment="Center"
Margin="10,0,0,0"
FontSize="18" />
</StackPanel>
</StackPanel>
</ScrollViewer>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Not sure what the actual problem is.
But seeing you are already binding the source to a property, you can always change the value of that in your code.
Do note that nothing will change on screen if you don't put Mode=OneWay to it. Because x:Bind default setting is Mode:OneTime
So instead of ImageSource="{x:Bind image_url}" put ImageSource="{x:Bind image_url, Mode=OneWay}"
Related
I'm using a grid view control in my uwp application and each grid view item contains a grid and a stackpanel. I want to make only grid to be clickable instead on the complete grid view item.
Here is my grid view code
<GridView
Grid.Row="1"
ItemsSource="{x:Bind ViewData}"
ScrollViewer.VerticalScrollBarVisibility="Hidden"
Margin="130,40,130,40">
<GridView.ItemTemplate>
<DataTemplate x:DataType="data:ViewArr">
<StackPanel Margin="50,25,50,25" >
<Grid Height="120" Width="120">
<Image
Source="assets/images/icons/check_my_blue.png"
Height="40"
Width="40"
Canvas.ZIndex="99"
Margin="80,0,0,80">
</Image>
<Canvas>
<Ellipse
Height="120"
Width="120"
Fill ="{x:Bind profile_color , FallbackValue='#00000'}"
StrokeThickness="3"
Stroke="Black" >
</Ellipse>
</Canvas>
<TextBlock
Text="{x:Bind profile_name}"
VerticalAlignment="Center"
HorizontalAlignment="Center"
FontSize="28"
Foreground="White">
</TextBlock>
</Grid>
<StackPanel>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,10,0,0">
<TextBlock Text="{x:Bind first_name}" FontSize="16" FontWeight="Bold" ></TextBlock>
<TextBlock Text="{x:Bind last_name}" FontSize="16" FontWeight="Bold"></TextBlock>
</StackPanel>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,10,0,0">
<TextBlock Text="Today - " FontSize="14" FontWeight="Bold" Foreground="Gray" Margin="0,0,5,0"></TextBlock>
<TextBlock Text="0" FontSize="14" Foreground="Gray"></TextBlock>
</StackPanel>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Center" Margin="0,10,0,0">
<TextBlock Text="Previous Tasks - " FontSize="14" FontWeight="Bold" Foreground="Gray" Margin="0,0,5,0"></TextBlock>
<TextBlock Text="0" FontSize="14" Foreground="Gray"></TextBlock>
</StackPanel>
</StackPanel>
</StackPanel>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
And it creates something like this.
https://i.stack.imgur.com/0UmIx.png
I want to make only circles to be clickable not the text below that.
Is there any way to achieve that? Please guide me. Thanks in advance.
How to make only a part of gridview item clickable in uwp application?
For your requirement, you could set GridView IsItemClickEnabled property as false then listen Grid Tapped event like following.
<GridView IsItemClickEnabled="False" >
<GridView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical">
<Grid Tapped="Grid_Tapped"
Width="30"
Height="30"
VerticalAlignment="Center"
Background="Red"
CornerRadius="15"
/>
<StackPanel VerticalAlignment="Center" Orientation="Vertical">
<TextBlock VerticalAlignment="Center" Text="NicoName" />
</StackPanel>
</StackPanel>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
private void Grid_Tapped(object sender, TappedRoutedEventArgs e)
{
}
Try this.
<GridView
Grid.Row="1"
Margin="130,40,130,40"
IsItemClickEnabled="False"
ScrollViewer.VerticalScrollBarVisibility="Hidden">
<GridView.ItemTemplate>
<DataTemplate>
<StackPanel Margin="50,25,50,25">
<Button
BorderBrush="Transparent"
BorderThickness="0"
Command="{Binding MyCommandName}"
Foreground="Transparent">
<Grid Width="120" Height="120">
<Image
Width="40"
Height="40"
Margin="80,0,0,80"
Canvas.ZIndex="99"
Source="assets/images/icons/check_my_blue.png" />
<Canvas>
<Ellipse
Width="120"
Height="120"
Fill="{x:Bind profile_color, FallbackValue='#00000'}"
Stroke="Black"
StrokeThickness="3" />
</Canvas>
<TextBlock
HorizontalAlignment="Center"
VerticalAlignment="Center"
FontSize="28"
Foreground="White"
Text="{x:Bind profile_name}" />
</Grid>
</Button>
<StackPanel>
<StackPanel
Margin="0,10,0,0"
HorizontalAlignment="Center"
Orientation="Horizontal">
<TextBlock
FontSize="16"
FontWeight="Bold"
Text="{x:Bind first_name}" />
<TextBlock
FontSize="16"
FontWeight="Bold"
Text="{x:Bind last_name}" />
</StackPanel>
<StackPanel
Margin="0,10,0,0"
HorizontalAlignment="Center"
Orientation="Horizontal">
<TextBlock
Margin="0,0,5,0"
FontSize="14"
FontWeight="Bold"
Foreground="Gray"
Text="Today - " />
<TextBlock
FontSize="14"
Foreground="Gray"
Text="0" />
</StackPanel>
<StackPanel
Margin="0,10,0,0"
HorizontalAlignment="Center"
Orientation="Horizontal">
<TextBlock
Margin="0,0,5,0"
FontSize="14"
FontWeight="Bold"
Foreground="Gray"
Text="Previous Tasks - " />
<TextBlock
FontSize="14"
Foreground="Gray"
Text="0" />
</StackPanel>
</StackPanel>
</StackPanel>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
I'm working on a project in which I'm setting content using JSON Binding in Grid view but now I want to get Text of item when it is selected. XAML CODE:
<GridView ItemsSource="{Binding}" HorizontalAlignment="Center" Margin="0,10,0,0" x:Name="dataList" VerticalAlignment="Center" SelectionMode="None" SelectionChanged="dataList_Selection">
<GridView.ItemTemplate>
<DataTemplate>
<StackPanel Width="450" Height="300">
<Image Source="{Binding Top}" Margin="0,0,0,0" Stretch="None" />
<TextBlock x:Name="title" Text="{Binding Title}" Foreground="Black" HorizontalAlignment="Center" FontFamily="Assets/Font/MixBrush.ttf#MixBrush" FontWeight="Bold" FontSize="50" Margin="0,10,0,0" />
<Image Source="{Binding Bottom}" Margin="0,0,0,0" Stretch="None" />
<TextBlock Text="{Binding first}" Foreground="Black" HorizontalAlignment="Center" FontFamily="Assets/Font/Comfortaa_Regular.ttf#Comfortaa" FontSize="20" Margin="0,50,0,0" />
<TextBlock Text="{Binding second}" Foreground="Black" HorizontalAlignment="Center" FontFamily="Assets/Font/Comfortaa_Regular.ttf#Comfortaa" FontSize="20" Margin="0,0,0,0" />
<TextBlock Text="{Binding third}" Foreground="Black" HorizontalAlignment="Center" FontFamily="Assets/Font/Comfortaa_Regular.ttf#Comfortaa" FontSize="20" Margin="0,0,0,0" />
</StackPanel>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
Here I want to get Text of "title" programmatically. Please share your knowledge with me. :-)
********************** Thank You ************************
On your back code use:
title.Text;
After long hard struggle I found my answer.
var selection = (myClass) dataList.SelectedItem;
await new MessageDialog(selection.Title).ShowAsync();
And I got perfect result.
Thank You.
Here is my xaml
<ListBox Margin="3,60,1,10" BorderThickness="2" Grid.Row="1" Name="lstAnnouncement" Tap="lstAnnouncement_Tap" Width="476" d:LayoutOverrides="VerticalMargin">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Name="thispanel" Grid.Row="1" Orientation="Horizontal" Height="120" Width="478" >
<StackPanel.Background>
<ImageBrush ImageSource="Images/Text-ALU.png" Stretch="Fill" />
<!--<SolidColorBrush Color="{Binding Path=background}"/>-->
</StackPanel.Background>
<toolkit:ContextMenuService.ContextMenu>
<toolkit:ContextMenu>
<toolkit:MenuItem Header="Delete" Click="MenuItem_Click"/>
<!--<toolkit:MenuItem Header="Remove " Click="MenuItem_Click"/>-->
</toolkit:ContextMenu>
</toolkit:ContextMenuService.ContextMenu>
<Grid HorizontalAlignment="Left" Width="30" Margin="0,0,0,2" Background="#FF0195D5" Height="118">
<!--<Grid.Background>
<ImageBrush ImageSource="Images/Text-ALU.png" Stretch="Fill" />
</Grid.Background>-->
<TextBlock x:Name="txtDate" TextWrapping="Wrap" Text="{Binding Path=announcementDate}" RenderTransformOrigin="0.5,0.5" Margin="-43.169,44.001,-43.831,0" UseLayoutRounding="False" d:LayoutRounding="Auto" TextAlignment="Center" Height="30" VerticalAlignment="Top" Width="117">
<TextBlock.RenderTransform>
<CompositeTransform Rotation="-90"/>
</TextBlock.RenderTransform>
</TextBlock>
</Grid>
<Grid HorizontalAlignment="Left" Width="5" Height="120"/>
<StackPanel Orientation="Vertical" VerticalAlignment="Top" Width="432" Height="114">
<TextBlock x:Name="txtTitle" Height="27" TextWrapping="Wrap" Text="{Binding Path=announcementTitle}" FontSize="18.667" HorizontalAlignment="Left" Width="432" FontWeight="Bold" />
<StackPanel Orientation="Horizontal" Width="432" Height="27">
<TextBlock x:Name="txtBy" FontWeight="Bold" Height="27" TextWrapping="Wrap" Text="{Binding Path=announcementBy}" FontSize="18.667" Width="399"/>
<Image x:Name="imgArrow" Width="25" Source="Images/Go-In-Arrow.png" Height="25" Margin="5,0,0,0"/>
</StackPanel>
<StackPanel Orientation="Horizontal" Width="433" Height="60">
<TextBlock x:Name="txtDesc" FontWeight="Bold" Height="58" TextWrapping="Wrap" Text="{Binding Path=announcementShortDescription}" FontSize="18.667" Width="371"/>
<TextBlock x:Name="txtID" Height="56" Text="{Binding Path=announcementID}" TextWrapping="Wrap" Foreground="Black" FontSize="18.667" Width="8" Visibility="Collapsed"/>
<Image x:Name="imgType" Width="35" Source="{Binding Path=announcementTypeImage}" Height="40" Margin="27,20,0,0" d:LayoutOverrides="Height"/>
</StackPanel>
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
i want to change foreground color of textblocxk with x:name txtDesc in code behind using c#
i am trying
txtDesc.Foreground = Brushes.White;
but it not recognizing it so how to achieve it? also is there any other way to change foreground colour using binding
As I said in the comments, the reason that your code is not compiling is because your TextBlock is part of a DataTemplate of a ListBox and not on object on the page itself. You'd therefore expect several instances to exist; how would can you identify them all with only one identifier?
You later mentioned in the comments that what you want to do is change the colour of the TextBlock in each list item according to the value of a property of the item. There are several ways to do it.
You could use Blend behaviours:
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Text="{Binding announcementShortDescription}" >
<Interactivity:Interaction.Behaviors>
<Core:DataTriggerBehavior Value="1" Binding="{Binding itemread}">
<Core:ChangePropertyAction PropertyName="Foreground">
<Core:ChangePropertyAction.Value>
<SolidColorBrush Color="Blue"/>
</Core:ChangePropertyAction.Value>
</Core:ChangePropertyAction>
</Core:DataTriggerBehavior>
</Interactivity:Interaction.Behaviors>
</TextBlock>
</DataTemplate>
</ListBox.ItemTemplate>
My preferred choice, though, would be to use a value converter. Something like:
class ItemReadToColorConverter : IValueConverter
{
public object Convert(object value, Type targetType, object parameter, string language)
{
int val = (int)value;
return val == 0 ? new SolidColorBrush(Colors.Black) : new SolidColorBrush(Colors.Blue);
}
public object ConvertBack(object value, Type targetType, object parameter, string language)
{
throw new NotImplementedException();
}
}
And in the XAML:
<ListBox x:Name="list">
<ListBox.Resources>
<local:ItemReadToColorConverter x:Key="conv" />
</ListBox.Resources>
<ListBox.ItemTemplate>
<DataTemplate>
<TextBlock Foreground="{Binding itemread, Converter={StaticResource conv}}" Text="{Binding announcementShortDescription}" />
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
try this:
Xaml:
<TextBlock x:Name="txtDesc" FontWeight="Bold" Height="58" TextWrapping="Wrap" Text="{Binding Path=announcementShortDescription}" FontSize="18.667" Width="371" Foreground="Yellow"/>
CS:
txtDesc.Foreground = new SolidColorBrush(Colors.Yellow);
I have been up and down looking on the internet and many people seem to have this problem but its generally solved by changing the container to a grid, constraining the height etc. etc. I can't to seem to get this to work.
I have an observableCollection thats feeding into a DataTemplate. I can't for th life of me get the scrollbar working. Its there but not enabling. Thanks Scott
<TabItem Header="select a call" x:Name="TabActiveCalls" Style="{DynamicResource MyTabItem}" FontFamily="QuickType">
<Grid Margin="0.125,0.412,3.125,0" Height="471" HorizontalAlignment="Stretch">
<StackPanel Orientation="Horizontal" Width="839.14" HorizontalAlignment="Left" VerticalAlignment="Top" Height="56">
<StackPanel Orientation="Vertical" HorizontalAlignment="Left" Margin="0,0,10,0" Width="741.14">
<StackPanel Height="28" Orientation="Horizontal" Width="733.14" HorizontalAlignment="Left">
<TextBlock x:Name="txtHistoryFound" TextWrapping="Wrap" Text="*" Foreground="#FFE20A0A" Visibility="Collapsed"/>
<TextBlock TextWrapping="Wrap" Text="filter by:" Margin="5,0,10,0" Foreground="#FF585AD4" VerticalAlignment="Center" HorizontalAlignment="Center"/>
<TextBlock TextWrapping="Wrap" Text="call no" Margin="5,0,2,0" VerticalAlignment="Center" Foreground="#FF5E88DA"/>
<TextBox Template="{StaticResource TextBoxBaseControlTemplate}" x:Name="searchCallNo" TextChanged="searchCallNo_TextChanged" TextWrapping="Wrap" Width="67" Foreground="#FF1341B1" TextAlignment="Center" Margin="5,0,10,0" Height="22" VerticalAlignment="Center" />
<TextBlock TextWrapping="Wrap" Text="postcode" Margin="5,0,2,0" VerticalAlignment="Center" Foreground="#FF5E88DA"/>
<TextBox Template="{StaticResource TextBoxBaseControlTemplate}" x:Name="searchPostcode" TextWrapping="Wrap" Width="67" Foreground="#FF1341B1" TextAlignment="Center" Margin="5,0,10,0" Height="22" VerticalAlignment="Center"/>
<TextBlock Height="23" x:Name="txtSiteName" FontSize="16" Foreground="#FF0E7C0B" Width="409" VerticalAlignment="Center" HorizontalAlignment="Left" Margin="0" TextAlignment="Right" Text="Airedale International Ltd" />
</StackPanel>
<StackPanel Width="733.14" HorizontalAlignment="Left">
<Border Height="21" Margin="5,6,8,0" CornerRadius="3,3,0,0" BorderThickness="1" BorderBrush="#FFC0BABA">
<StackPanel Orientation="Horizontal" Background="#FFD0D5DE">
<TextBlock TextWrapping="Wrap" Text="CALL NO. / DATE DUE/ CUSTOMER" Margin="5,0,0,0" Foreground="{DynamicResource ListTitle}" FontSize="10.667" VerticalAlignment="Center"/>
<TextBlock TextWrapping="Wrap" Text="ENGINEER / ADDRESS" Margin="114,0,0,0" Foreground="{DynamicResource ListTitle}" VerticalAlignment="Center"/>
<TextBlock TextWrapping="Wrap" Text="REPORT" Margin="43,0,0,0" Foreground="{DynamicResource ListTitle}" RenderTransformOrigin="2.543,0.429" VerticalAlignment="Center"/>
<TextBlock TextWrapping="Wrap" Text="CALL" Margin="28,0,0,0" Foreground="{DynamicResource ListTitle}" RenderTransformOrigin="2.543,0.429" VerticalAlignment="Center"/>
<TextBlock TextWrapping="Wrap" Text="POSITION" Margin="43,0,0,0" Foreground="{DynamicResource ListTitle}" RenderTransformOrigin="2.543,0.429" VerticalAlignment="Center"/>
</StackPanel>
</Border>
</StackPanel>
</StackPanel>
<Image Height="56" Width="90" Source="/ComfortReportEng;component/Media/Images/comfort_group.png"/>
</StackPanel>
<ListBox ItemTemplate="{StaticResource DataTemplateReportList}" ItemsSource="{Binding Source={StaticResource cvsReportList}}"
Margin="5,56,8,0" MaxHeight="415" Height="415" ScrollViewer.VerticalScrollBarVisibility="Auto" ScrollViewer.CanContentScroll="True"/>
</Grid>
</TabItem>
many thanks for getting back. Here is my DataTempate
<DataTemplate x:Key="DataTemplateReportList">
<Border Margin="0,2,0,0" BorderThickness="1" BorderBrush="#FFA19C9C" CornerRadius="3,3,0,0" Width="810.52" Height="50" >
<Grid Background="#FF737B89" Height="48" >
<StackPanel Orientation="Vertical" HorizontalAlignment="Left" Width="274" VerticalAlignment="Top" >
<StackPanel Height="23" Orientation="Horizontal" Margin="0">
<TextBlock TextWrapping="Wrap" Text="{Binding CallNo, Mode=TwoWay}" Foreground="#FF7DF51E" Margin="5,0,0,0" FontFamily="Verdana"/>
<TextBlock TextWrapping="Wrap" Text="{Binding DateDue, Mode=TwoWay, StringFormat=d}" Foreground="White" Margin="5,0,0,0" FontFamily="Verdana"/>
</StackPanel>
<StackPanel Height="23" Orientation="Horizontal">
<TextBlock TextWrapping="Wrap" Text="{Binding CompanyName, Mode=TwoWay}" Foreground="#FFFFEA00" Margin="5,0,0,0" FontFamily="Verdana"/>
</StackPanel>
</StackPanel>
<StackPanel HorizontalAlignment="Left" Width="456" Orientation="Vertical" Height="46" Margin="274,1,0,1" VerticalAlignment="Top">
<StackPanel Height="23" Orientation="Horizontal">
<TextBlock TextWrapping="Wrap" Text="{Binding EngineerName, Mode=TwoWay}" Foreground="#FFCAE5C6" Margin="5,0,0,0" FontFamily="Verdana" Width="140"/>
<TextBlock TextWrapping="Wrap" Text="{Binding ReportStatus, Mode=TwoWay}" Foreground="#FF7DF51E" Margin="20,0,0,0" FontFamily="Verdana" Width="50"/>
<TextBlock TextWrapping="Wrap" Text="{Binding CallStatus, Mode=TwoWay}" Foreground="#FF7DF51E" Margin="20,0,0,0" FontFamily="Verdana" Width="50"/>
<TextBlock TextWrapping="Wrap" Text="{Binding Position, Mode=TwoWay}" Foreground="White" Margin="20,0,0,0" FontFamily="Verdana" Width="50"/>
</StackPanel>
<StackPanel Height="23" Orientation="Horizontal">
<TextBlock TextWrapping="Wrap" Text="{Binding Address, Mode=TwoWay}" Foreground="#FFFFEA00" Margin="5,0,0,0" FontFamily="Verdana" Width="483.12"/>
</StackPanel>
</StackPanel>
<Grid Width="56" HorizontalAlignment="Right" Margin="0,0,12.52,0" VerticalAlignment="Top">
<Image Name="imgInfo" Source="/ComfortReportEng;component/Media/Images/Info4.png" Margin="24,8,0,0" Cursor="Hand" MouseLeftButtonDown="imgInfo_MouseLeftButtonDown"/>
</Grid>
</Grid>
</Border>
</DataTemplate>
Must be a bug. I have the following only..
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
x:Class="ComfortReportEng.Views.EngineerReport.EngineerReport"
Title="Engineer Report" WindowStartupLocation="CenterScreen" Loaded="Window_Loaded" SizeToContent="WidthAndHeight" >
<Window.Resources>
<CollectionViewSource x:Key="cvsReportList"/>
</Window.Resources>
<Grid Margin="0.125,0.412,3.125,0" Height="471">
<ListBox Margin="23,64,3,0" Width="834.14" ItemsSource="{Binding Source={StaticResource cvsReportList}}"
x:Name="lbReportList" SelectionChanged="lbReportList_SelectionChanged" Background="#FFEEEFE4" />
</Grid>
and code is
private void LoadReportList()
{
int number = 0;
List<int> myNumbers = new List<int>();
while (number < 80)
{
myNumbers.Add(number);
number += 1;
}
_cvsReportList = (CollectionViewSource)(this.FindResource("cvsReportList"));
_cvsReportList.Source = myNumbers;
}
This was copied over from another project. Completely confused. Please don't worry. It's not a logical problem. Please take this as a close call with no solution. Cheers again Scott
Just to give this completeness. I am not sure why this happens but here is it.
if (System.Environment.MachineName == "SCOTT-PC")
{
this.txtUserName.Text = "Scott Fisher";
this.txtPassword.Password = "palace";
//LoginOK();
}
else
Keyboard.Focus(this.txtUserName);
If I clear the comments on LoginOK procedure I will get no scrollbar. With it commented and I interact with the login screen then everything is fine. Finally here is the code for the LoginOK.
if (LoginService.CheckLogin(txtUserName.Text, txtPassword.Password.ToString()))
{
Helpers.User.ThisUser = this.txtUserName.Text;
EngineerReport.EngineerReport engReport = new EngineerReport.EngineerReport()
{
Owner = Window.GetWindow(this),
WindowStartupLocation =
System.Windows.WindowStartupLocation.
CenterOwner
};
this.Hide();
engReport.ShowDialog();
}
else
{
this.txtPassword.Password = "";
this.txtPassword.Focus();
}
Can you provide you DataTemplate as I believe I have just managed to mock up what you are trying to achieve and I have scrollbars visible and working form the start.
Here is the xaml that I used for the DataTemplate for the ListBox:
<ListBox DataContext="{StaticResource MusicData}" ItemsSource="{Binding XPath=Album}">
<ListBox.ItemTemplate>
<DataTemplate>
<ListBoxItem>
<StackPanel Orientation="Horizontal" >
<TextBlock>No.</TextBlock>
<TextBlock Text="{Binding XPath=No}"></TextBlock>
<TextBlock>Title</TextBlock>
<TextBlock Text="{Binding XPath=Title}"></TextBlock>
</StackPanel>
</ListBoxItem>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Hope this helps.
I also found a piece of code I used a while back and this might help. You can try setting the ItemsPanelTemplate:
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel>
<ScrollViewer VerticalScrollBarVisibility="Visible" />
</StackPanel>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
This will work with any items control as stated in this article:
http://msdn.microsoft.com/en-us/library/system.windows.controls.itemscontrol.itemcontainerstyle.aspx
One final thing I can suggest is to create your own ControlTemplate for the ListBox Like so:
<ListBox.Template>
<ControlTemplate>
<ScrollViewer VerticalScrollBarVisibility="Auto">
<ItemsPresenter />
</ScrollViewer>
</ControlTemplate>
</ListBox.Template>
I have data binding to a listbox, and texttrimming property set to WordEllipsis, but it doesn't seem to work. The textblocks are showing text as if they do without the texttrimming property set. This is my xaml code. Please help.
<Grid>
<Grid.Resources>
<application:ViewModel x:Key="ViewModel"/>
</Grid.Resources>
<TextBlock Height="75" TextWrapping="Wrap" Text="Click on Settings to search for quotes (by author or by query)." VerticalAlignment="Top" TextAlignment="Center" FontSize="26.667"/>
<ListBox Margin="0,166,0,0" Name="lstQuote" DoubleTap="lstQuote_DoubleTap" Hold="lstQuote_Hold">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<es:RegularPolygon Fill="#FFF4F4F5" Height="90" InnerRadius="0.47211" PointCount="5" Stretch="Fill" Stroke="Black" UseLayoutRounding="False" Width="84"/>
<StackPanel Orientation="Vertical" Margin="0,10,0,0">
<TextBlock Text="{Binding Author}" TextWrapping="Wrap" FontSize="24"/>
<TextBlock Text="{Binding Quote}" TextWrapping="NoWrap" FontSize="30" TextTrimming="WordEllipsis" Width="Auto" />
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<Button Content="Random Quote" Height="79" Margin="48,83,44,0" VerticalAlignment="Top" x:Name="quotSearch" Click="quotSearch_Click" />
</Grid>
change TextBox Width properties to fixed width
<TextBlock Width="200" Height="75" TextWrapping="Wrap" Text="Click on Settings to search for quotes (by author or by query)." VerticalAlignment="Top" TextAlignment="Center" FontSize="26.667"/>