this is the code that is driving me insane. It works great on windows 8(Snap View), but when I try to run the same XAML in my windows phone 7 app, it doesn't work.
WHAT HAPPENS
The app runs fine, but the problem is that the screen is blank. I have tried to add some background to the itemtemplate, and it does show up which means that maybe the databinding is working. But the content of the 5 textblock's doesn't show.
<ListBox x:Name="result_s" Margin="0,296,0,0" HorizontalAlignment="Center" VerticalAlignment="Top">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Margin="8,8,48,8" Orientation="Horizontal" Height="80">
<TextBlock HorizontalAlignment="Left" VerticalAlignment="Bottom" FontSize="24" Width="auto" TextWrapping="Wrap" Margin="0,0,0,0" Text="{Binding coeff}"/>
<TextBlock HorizontalAlignment="Left" VerticalAlignment="Bottom" FontSize="24" Width="auto" TextWrapping="Wrap" Margin="4,0,0,0" Text="{Binding x}"/>
<TextBlock HorizontalAlignment="Left" VerticalAlignment="Bottom" FontSize="24" Width="auto" TextWrapping="Wrap" Margin="0,0,0,16" Text="{Binding xPow}"/>
<TextBlock HorizontalAlignment="Left" VerticalAlignment="Bottom" FontSize="24" Width="auto" TextWrapping="Wrap" Margin="4,0,0,0" Text="{Binding y}"/>
<TextBlock HorizontalAlignment="Left" VerticalAlignment="Bottom" FontSize="24" Width="auto" TextWrapping="Wrap" Margin="0,0,0,16" Text="{Binding yPow}"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Here is the code behind
void func()
{
ObservableCollection<Equation> answer = new ObservableCollection<Equation>();
// SOME CODE GOES IN HERE, THE CODE POPULATES answer
result_s.ItemsSource = null;
result_s.ItemsSource = answer;
}
Please, can you see any reason this won't work.
Related
I intend to connect 2 or more USB audio adapter (each with mic & line) to my raspberry pi 3. Therefore I need to enumerate the audio devices for audio render and audio capture respectively and display them on a listbox similar to audioinsample .
I do not understand how to come about it.
I tried playing with the codes below, exception handler occurred.
Please advise.
Thanks.
captureDeviceList = new ObservableCollection<DeviceInformation>();
audioCaptureList.ItemsSource = captureDeviceList;
renderDeviceList = new ObservableCollection<DeviceInformation>();
audioRenderList.ItemsSource = renderDeviceList;
private async void enumerateAudioDevice()
{
var renderDevices = await DeviceInformation.FindAllAsync(DeviceClass.AudioRender);
if (renderDevices.Count > 0)
{
for (var i = 0; i < renderDevices.Count; i++)
{
renderDeviceList.Add(renderDevices[i]);
}
audioRenderList.SelectedItem = renderDevices[0];
}
var captureDevices = await DeviceInformation.FindAllAsync(DeviceClass.AudioCapture);
if (captureDevices.Count > 0)
{
for (var i = 0; i < captureDevices.Count; i++)
{
captureDeviceList.Add(captureDevices[i]);
}
audioCaptureList.SelectedItem = captureDevices[0];
}
}
<PivotItem Header="Info">
<Grid>
<ListBox x:Name="audioRenderList" HorizontalAlignment="Left" Height="100" VerticalAlignment="Top" Width="288" Margin="0,25,0,0" FontSize="10"/>
<ListBox x:Name="audioCaptureList" HorizontalAlignment="Left" Height="100" VerticalAlignment="Top" Width="288" Margin="318,25,0,0" FontSize="10"/>
<TextBlock x:Name="renderDeviceCount" HorizontalAlignment="Left" Margin="248,0,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="40"/>
<TextBlock x:Name="captureDeviceCount" HorizontalAlignment="Left" Margin="566,0,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="40" RenderTransformOrigin="0.425,-0.5"/>
<TextBlock HorizontalAlignment="Left" Margin="318,0,0,0" TextWrapping="Wrap" Text="Capture Devices" VerticalAlignment="Top"/>
<TextBlock HorizontalAlignment="Left" TextWrapping="Wrap" Text="Render Devices" VerticalAlignment="Top"/>
<ListBox x:Name="usbList" HorizontalAlignment="Left" Height="100" Margin="0,158,0,0" VerticalAlignment="Top" Width="288"/>
<TextBlock HorizontalAlignment="Left" TextWrapping="Wrap" Text="USB Devices" VerticalAlignment="Top" Margin="0,133,0,0"/>
<TextBlock x:Name="usbDeviceCount" HorizontalAlignment="Left" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Margin="248,133,0,0" Width="40"/>
</Grid>
</PivotItem>
Updated:
I have modified my XAML code .. it works.. but seems like I can't get the stack panel margin arranged correctly.
I have my code below. Any advise?
Thanks.
<PivotItem Header="Info">
<Grid>
<ListBox x:Name="audioRenderList" Margin="10,28,358,144" Width="250" Height="90">
<ListBox.ItemTemplate>
<DataTemplate x:DataType="device:DeviceInformation">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{x:Bind Path=Name, Mode=OneWay}" Margin="0,0,0,0" FontSize="18"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<ListBox x:Name="audioCaptureList" Margin="344,28,10,144" Width="250" Height="90">
<ListBox.ItemTemplate>
<DataTemplate x:DataType="device:DeviceInformation">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{x:Bind Path=Name, Mode=OneWay}" Margin="0,0,0,0" FontSize="18"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<TextBlock x:Name="renderDeviceCount" HorizontalAlignment="Left" Margin="220,4,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="40"/>
<TextBlock x:Name="captureDeviceCount" HorizontalAlignment="Left" Margin="560,4,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="40" RenderTransformOrigin="0.425,-0.5"/>
<TextBlock HorizontalAlignment="Left" Margin="350,4,0,0" TextWrapping="Wrap" Text="Capture Devices" VerticalAlignment="Top"/>
<TextBlock HorizontalAlignment="Left" TextWrapping="Wrap" Text="Render Devices" VerticalAlignment="Top" Margin="10,4,0,0"/>
<ListBox x:Name="usbList" Margin="10,156,358,16" Width="250" Height="90">
<ListBox.ItemTemplate>
<DataTemplate x:DataType="device:DeviceInformation">
<StackPanel Orientation="Horizontal">
<TextBlock Text="{x:Bind Path=Name, Mode=OneWay}" Margin="0,0,0,0" FontSize="18" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<TextBlock HorizontalAlignment="Left" TextWrapping="Wrap" Text="USB Storage" VerticalAlignment="Top" Margin="10,131,0,0"/>
<TextBlock x:Name="usbDeviceCount" HorizontalAlignment="Left" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Margin="220,131,0,0" Width="40" RenderTransformOrigin="0.575,-0.75"/>
</Grid>
</PivotItem>
</Pivot>
Updated 09-10-2017
Because without your code in xaml,I am not sure your way of data binding.There are several reasons cause this problem.Please reference below source, maybe you need do some modification so that can fit your reqiurement.In addition, you should add xmlns:device="using:Windows.Devices.Enumeration" in the tag of page.
<Page
x:Class="AudioInSample.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:AudioInSample"
xmlns:device="using:Windows.Devices.Enumeration"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="White">
<StackPanel Margin="10" MinWidth="500">
<ListBox x:Name="audioCaptureList">
<ListBox.ItemTemplate>
<DataTemplate x:DataType="device:DeviceInformation">
<StackPanel>
<TextBlock Text="{x:Bind Path=Name, Mode=OneWay}" Margin="12, 15, 12, 0" FontSize="18.667" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
<ListBox x:Name="audioRenderList">
<ListBox.ItemTemplate>
<DataTemplate x:DataType="device:DeviceInformation">
<StackPanel>
<TextBlock Text="{x:Bind Path=Name, Mode=OneWay}" Margin="12, 15, 12, 0" FontSize="18.667" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</StackPanel>
</Grid>
I have a gridview in a store app which is dynamically bound to a Collection
<GridView x:Name="Gridview1" Height="180" HorizontalAlignment="Left" VerticalAlignment="Top"
ScrollViewer.HorizontalScrollMode="Disabled" SelectionMode="None" >
<GridView.ItemTemplate>
<DataTemplate >
<Border Background="White" BorderBrush="LightGray" BorderThickness="3" Height="150" Width="150" Tapped="peopleDashboard_Tapped" PointerEntered="Gridview1_PointerEntered" PointerExited="Gridview1_PointerExited" >
<Grid Margin="5" >
<TextBlock Text="{Binding TileName}" FontSize="18" HorizontalAlignment="Center" VerticalAlignment="Top"
TextWrapping="Wrap" TextAlignment="Center"></TextBlock>
<TextBlock Text="{Binding TileValue}" Foreground="Orange" FontSize="18" VerticalAlignment="Bottom" HorizontalAlignment="Center"
TextWrapping="Wrap" TextAlignment="Center"></TextBlock>
</Grid>
</Border>
</DataTemplate>
</GridView.ItemTemplate>
</GridView>
And I am binding this gridview in code behind like this
Gridview1.ItemsSource = listObj;
I will get 7 boxes . on hover gridview has a hover border color for each item.
I need to disable just one particular item in the gridview.
I can write Gridview1.IsEnabled = false for disabling the whole gridview.
But I need to disable only a particular item.
Here is a picture of the populated gridview
this is the disabled gridview.
I need to disable only one box in the gridview.
Any possible suggestions ?
you can try it with IValue Converter. When binding the data if Value is 'InProgress' make it disable, something like this you want I think. Try googling how to use IValue Converter.
many years later....I stumbled upon this problem myself when trying to make some inactive items in my UWP project..my solution was to employ use of the extended DataTemplateSelector that allows one to enable/disable the gridview item based on the associated class object's properties as described here:
https://www.jerriepelser.com/blog/disable-item-selection-winrt-gridview/
<Page.Resouces>
<DataTemplate x:Name "ActiveItem" >
<Border Background="White" BorderBrush="LightGray" BorderThickness="3" Height="150" Width="150" Tapped="peopleDashboard_Tapped" PointerEntered="Gridview1_PointerEntered" PointerExited="Gridview1_PointerExited" >
<Grid Margin="5" >
<TextBlock Text="{Binding TileName}" FontSize="18" HorizontalAlignment="Center" VerticalAlignment="Top"
TextWrapping="Wrap" TextAlignment="Center"></TextBlock>
<TextBlock Text="{Binding TileValue}" Foreground="Orange" FontSize="18" VerticalAlignment="Bottom" HorizontalAlignment="Center"
TextWrapping="Wrap" TextAlignment="Center"></TextBlock>
</Grid>
</Border>
</DataTemplate>
<DataTemplate x:Name "InactiveItem" >
<Border Background="White" BorderBrush="LightGray" BorderThickness="3" Height="150" Width="150" Tapped="peopleDashboard_Tapped" PointerEntered="Gridview1_PointerEntered" PointerExited="Gridview1_PointerExited" >
<Grid Margin="5" >
<TextBlock Text="{Binding TileName}" FontSize="18" HorizontalAlignment="Center" VerticalAlignment="Top"
TextWrapping="Wrap" TextAlignment="Center"></TextBlock>
<TextBlock Text="{Binding TileValue}" Foreground="Orange" FontSize="18" VerticalAlignment="Bottom" HorizontalAlignment="Center"
TextWrapping="Wrap" TextAlignment="Center"></TextBlock>
</Grid>
</Border>
</DataTemplate>
<local:SelectionItemTemplateSelector x:Key="DataTemplateSelector" ActiveItemDataTemplate="{StaticResource ActiveItem}" InactiveItemTemplate="{StaticResource InactiveItem}"/>
</Page.Resources>
<GridView x:Name="Gridview1" Height="180" HorizontalAlignment="Left" VerticalAlignment="Top"
ScrollViewer.HorizontalScrollMode="Disabled" SelectionMode="None" ItemTemplateSelector="{StaticResource DataTemplateSelector}" >
</GridView>
I'm making a Windows Phone 8 App with C# and I'm trying to display the output of XML to a Pivot page with several listboxes, the only hurdle standing in my way is the alignment of the items in the ingredients box, they appear like this:
Table Salt
1
Pinch
When I actually want them to appear like this
Table Salt
1 Pinch
Basically each item appears on a separate line and through messing around with stack panels I can't seem to get anything to appear on the same line, this is the xaml code I'm using currently:
<Grid x:Name="ContentPanel1" Grid.Row="1" Margin="12,0,12,0">
<ListBox Height="600" HorizontalAlignment="Left" Margin="21,6,0,0" Name="ingredientsList" VerticalAlignment="Bottom" Width="413">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock x:Name="lbl_Name" TextWrapping="Wrap" FontSize="20" Margin="0,10,0,0" Text="{Binding IngredientName}" Foreground="White" FontWeight="Bold"/>
<TextBlock x:Name="lbl_Quantity" TextWrapping="Wrap" FontSize="20" Margin="0,0,0,0" Text="{Binding IngredientQuantity}" Foreground="White"/>
<TextBlock x:Name="lbl_Unit" TextWrapping="Wrap" FontSize="20" Margin="0,0,0,0" Text="{Binding IngredientUnit}" Foreground="White"/>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
Can anyone suggest a fix? Thanks in advance!
If it were me I would nest another stack panel in your Data Template
<DataTemplate>
<StackPanel Orientation="Vertical">
<TextBlock x:Name="lbl_Name" TextWrapping="Wrap" FontSize="20" Margin="0,10,0,0" Text="{Binding IngredientName}" Foreground="White" FontWeight="Bold"/>
<StackPanel Orientation="Horizontal">
<TextBlock x:Name="lbl_Quantity" TextWrapping="Wrap" FontSize="20" Margin="0,0,0,0" Text="{Binding IngredientQuantity}" Foreground="White"/>
<TextBlock x:Name="lbl_Unit" TextWrapping="Wrap" FontSize="20" Margin="0,0,0,0" Text="{Binding IngredientUnit}" Foreground="White"/>
</StackPanel>
</StackPanel>
</DataTemplate>
A StackPanel stacks contained items vertically. You could use one single TextBlock with two run elements:
<StackPanel>
<TextBlock x:Name="lbl_Name" TextWrapping="Wrap" FontSize="20" Margin="0,10,0,0" Text="{Binding IngredientName}" Foreground="White" FontWeight="Bold"/>
<TextBlock x:Name="lbl_Quantity" TextWrapping="Wrap" FontSize="20" Margin="0,0,0,0" Foreground="White">
<Run Text="{Binding IngredientQuantity}" />
<Run Text="{Binding IngredientUnit}" />
</TextBlock>
</StackPanel>
May be like this
<Grid x:Name="ContentPanel1" Grid.Row="1" Margin="12,0,12,0">
<ListBox Height="600" HorizontalAlignment="Left" Margin="21,6,0,0" Name="ingredientsList" VerticalAlignment="Bottom" Width="413">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock x:Name="lbl_Name" TextWrapping="Wrap" FontSize="20" Margin="0,10,0,0" Text="{Binding IngredientName}" Foreground="White" FontWeight="Bold"/>
<StackPanel Orientation="Horizontal">
<TextBlock x:Name="lbl_Quantity" TextWrapping="Wrap" FontSize="20" Margin="0,0,0,0" Text="{Binding IngredientQuantity}" Foreground="White"/>
<TextBlock x:Name="lbl_Unit" TextWrapping="Wrap" FontSize="20" Margin="10,0,0,0" Text="{Binding IngredientUnit}" Foreground="White"/>
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
Use StackPanel property Orientation="Horizontal"
<Grid x:Name="ContentPanel1" Grid.Row="1" Margin="12,0,12,0">
<ListBox Height="600" HorizontalAlignment="Left" Margin="21,6,0,0" Name="ingredientsList" VerticalAlignment="Bottom" Width="413">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel>
<TextBlock x:Name="lbl_Name" TextWrapping="Wrap" FontSize="20" Margin="0,10,0,0" Text="{Binding IngredientName}" Foreground="White" FontWeight="Bold"/>
<StackPanel Orientation="Horizontal">
<TextBlock x:Name="lbl_Quantity" TextWrapping="Wrap" FontSize="20" Margin="0,0,0,0" Text="{Binding IngredientQuantity}" Foreground="White"/>
<TextBlock x:Name="lbl_Unit" TextWrapping="Wrap" FontSize="20" Margin="0,0,0,0" Text="{Binding IngredientUnit}" Foreground="White"/>
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
I have a listbox in my windows phone application. In the listbox DataTemplate I placed a button. How can I get the button object in codebehind. I am not getting the reference of the rowButton in the .cs file. I want to change the button background color of button of each row. how can I get the button reference in the code behind ?
I following code I used for listview.
<Grid Height="530" Grid.Row="1" VerticalAlignment="Top" Margin="0,30,0,0">
<ListBox Margin="0,0,0,0" Name="TransactionList">
<ListBox.ItemTemplate>
<DataTemplate>
<Button Width="460" Height="150" Click="user_click" Name="rowButton" >
<Button.Content>
<StackPanel Orientation="Horizontal" Height="auto" Width="400">
<Image Width="80" Height="80" Source="{Binding Type}"></Image>
<StackPanel Orientation="Vertical" Height="150" Margin="20,0,0,0">
<StackPanel Orientation="Horizontal" Height="40">
<TextBlock Width="100" FontSize="22" Text="Name :" Height="40" ></TextBlock>
<TextBlock Width="auto" FontSize="22" Text="{Binding Name}" Height="40" ></TextBlock>
</StackPanel>
<StackPanel Orientation="Horizontal" Height="40">
<TextBlock Width="100" FontSize="22" Text="Date :" Height="40" ></TextBlock>
<TextBlock Width="100" FontSize="22" Text="{Binding Date}" Height="40" ></TextBlock>
</StackPanel>
<StackPanel Orientation="Horizontal" Height="40">
<TextBlock Width="100" FontSize="22" Text="Amount :" Height="40" ></TextBlock>
<TextBlock Width="auto" FontSize="22" Text="{Binding Amount}" Height="40" ></TextBlock>
<TextBlock Width="auto" FontSize="22" Text=" $" Height="40" ></TextBlock>
</StackPanel>
</StackPanel>
</StackPanel>
</Button.Content>
</Button>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
If you want to change background on user click, in the click event handler use
Button button1 = sender as Button;
button1.Backgorund = new SolidColorBrush(Colors.Red);
to change the background color.
Else bind the background property for each button and change its value on iteration of the items in the listbox.
Without seeing how you've tried to access this is in code it's impossible to say why what you're doing isn't working.
However it'll be much easier if you use databinding to set the color of the templateitem
I have a twitter feed in a list box in a app I'm making for Windows Phone 7. The problem I'm having is that the text of a tweet is being cut off the edge of the list box instead of wrapping around to a new line like this:
The list box is inside a panorama which works fine. This is my code:
<ListBox x:Name="cheapyListBox" Height="500" HorizontalAlignment="Left" Margin="0,0,0,0" VerticalAlignment="Top" Width="400" ScrollViewer.VerticalScrollBarVisibility="Hidden" HorizontalContentAlignment="Left" >
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Height="132" Tap="Message_OnTap">
<Image Source="{Binding ImageSource}" Height="73" Width="73" VerticalAlignment="Top" Margin="0,10,8,0"/>
<StackPanel Width="Auto">
<!--<TextBlock Text="{Binding UserName}" FontSize="28" Margin="12,0,0,0" /> -->
<TextBlock Text="{Binding Message}" TextWrapping="Wrap" FontSize="24" />
<TextBlock Text="{Binding Date}" TextWrapping="Wrap" FontSize="20" />
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
How can I get the tweet text to wrap round instead of being cut off? Thank you.
Since your inner StackPanel is nested within a horizontal Stackpanel, it has no constraint of depth, and so the TextBlocks expand infinitely as the text becomes longer.
There are a variety of ways you can fix the issue, but an easy one (if you know the width that you want) is to set the inner StackPanel's width to a finite number.
For example:
<ListBox x:Name="cheapyListBox" Height="500" HorizontalAlignment="Left" Margin="0,0,0,0" VerticalAlignment="Top" Width="400" ScrollViewer.VerticalScrollBarVisibility="Hidden" HorizontalContentAlignment="Left" >
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Height="132" Tap="Message_OnTap">
<Image Source="{Binding ImageSource}" Height="73" Width="73" VerticalAlignment="Top" Margin="0,10,8,0"/>
<StackPanel Width="400">
<!--<TextBlock Text="{Binding UserName}" FontSize="28" Margin="12,0,0,0" /> -->
<TextBlock Text="{Binding Message}" TextWrapping="Wrap" FontSize="24" />
<TextBlock Text="{Binding Date}" TextWrapping="Wrap" FontSize="20" />
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Hope this helps!