Second WPF window is blank - c#

The second window in my WPF window is blank.
I've tried declaring the variable in multiple places, and assigning the value of new Send() separately from the declaration.
I've also made sure it isn't just my computer. I sent the compiled program to someone else and it did the same thing.
private void Button_Click(object sender, RoutedEventArgs e)
{
Send send = new Send();
send.Show();
}
The Send class:
public partial class Send : Window
{
public Send()
{
InitializeComponent();
ipIdBox.Text = GenerateIPID(GetIPAddress(), 8000);
}
private string GetIPAddress()
{
var host = Dns.GetHostEntry(Dns.GetHostName());
foreach (var ip in host.AddressList)
{
if (ip.AddressFamily == AddressFamily.InterNetwork)
{
return ip.ToString();
}
}
throw new Exception("No network adapters with an IPv4 address in the system!");
}
private string GenerateIPID(string ip, int port)
{
string[] ipseps = ip.Split('.'); // Split IP into parts
string code = ""; // Initialize the code
int counter = 0; // A counter (because every 4 digits are seperated)
foreach (string ippart in ipseps)
{
int ipparti = Convert.ToInt32(ippart);
string hippart = ipparti.ToString("X2");
code += hippart;
counter++;
if (counter == 1) {
counter = 0;
code += "-";
}
}
code += $"-{port.ToString("X4")}";
return code;
}
}
... and it's XAML
<Window x:Class="ScistMain.Send"
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:ScistMain"
mc:Ignorable="d"
Title="Send" Height="264.95" Width="451.774" OverridesDefaultStyle="True" Topmost="True">
<Grid>
<TextBlock x:Name="ipIdBox" Margin="0,124,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Height="34" TextAlignment="Center" FontSize="24" Text="7F00-0001-8000"/>
<TextBlock Margin="0,108,0,0" TextWrapping="Wrap" Text="Tell the person recieving to type this code:" VerticalAlignment="Top" Width="444" TextAlignment="Center"/>
<TextBlock Margin="0,10,0,0" TextWrapping="Wrap" Text="You are sending:" VerticalAlignment="Top" TextAlignment="Center" FontSize="18" FontWeight="Bold"/>
<Image x:Name="iconImg" Height="32" Margin="206,39,206,0" VerticalAlignment="Top" Width="32" Source="Resources/scist.ico"/>
<TextBlock Margin="0,76,0,0" TextWrapping="Wrap" Text="Placeholder Program" VerticalAlignment="Top" TextAlignment="Center"/>
<ProgressBar x:Name="pBar" HorizontalAlignment="Left" Height="34" Margin="10,124,0,0" VerticalAlignment="Top" Width="424" Visibility="Collapsed"/>
<Button Content="Cancel" HorizontalAlignment="Left" Margin="359,203,0,0" VerticalAlignment="Top" Width="75"/>
</Grid>
</Window>
I expect it to show the window I created in the designer:
but instead it shows a black window.

OverridesDefaultStyle="True" on the Window tag was the issue.

Related

How to embed video Files in WPF C# and change sources

I am working on an interactive app that shows different video's based on different stages, I am using C# and WPF and I am trying to use a MediaElement and change it source but it only let me play 1 video file and will not change to the next video, it will keep playing the same file over and over again, I just can't seem to understand why is this happening, I also couldn't find a solution to this online, I have embedded both video files "Stage8.mp4" and "Stage12.mp4" in my solution explorer, Both video files are set to copy if newer and content, also I don't think there is something wrong in the path because if I switch between them it will play the correct file, it just won't change the source in real time.
here are my codes:
C#:
using System;
using System.Windows;
namespace WPF_Tester
{
/// <summary>
/// Interaction logic for MainWindow.xaml
/// </summary>
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
string NameChecker;
byte stage = 0;
private void BTN1_Click(object sender, RoutedEventArgs e)
{
NameChecker = "Name: " + TXT1.Text + " Last: " + TXT2.Text;
if (testlistview.Items.Contains(NameChecker))
{
MessageBox.Show("The name already exists.");
}
else
{
testlistview.Items.Add(NameChecker);
}
if (stage == 0)
{
TestElement.Source = new Uri("Stage12.mp4", UriKind.Relative);
TestElement.Play();
stage = 1;
}
if (stage == 1)
{
TestElement.Source = new Uri("Stage8.mp4", UriKind.Relative);
TestElement.Play();
stage = 0;
}
}
}
}
XAML:
<Window x:Class="WPF_Tester.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_Tester"
mc:Ignorable="d"
Title="MainWindow" Height="450" Width="800">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition></ColumnDefinition>
<ColumnDefinition></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBlock Text="Name:" FontSize="20" Margin="20,40,0,0" HorizontalAlignment="Left" VerticalAlignment="Top"></TextBlock>
<TextBox x:Name="TXT1" HorizontalAlignment="Left" VerticalAlignment="Top" FontSize="18" Margin="80,40,0,0" MinWidth="30"></TextBox>
<TextBlock Text="Last Name:" Grid.Column="0" Grid.Row="0" FontSize="20" Margin="20,80,0,0" HorizontalAlignment="Left" VerticalAlignment="Top"></TextBlock>
<TextBox x:Name="TXT2" HorizontalAlignment="Left" VerticalAlignment="Top" FontSize="18" Margin="120,80,0,0" MinWidth="30"></TextBox>
<Button x:Name="BTN1" HorizontalAlignment="Left" VerticalAlignment="Top" Content="Add Name" FontSize="20" Margin="20,180,0,0" Click="BTN1_Click"></Button>
<!-- here we set controls for the second column.-->
<ListView x:Name="testlistview" Grid.Column="1" Margin="20,40,20,20" FontSize="20" ></ListView>
<MediaElement Name="TestElement" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="0,200,20,0" UnloadedBehavior="Manual" Source="/Stage12.mp4" LoadedBehavior="Play"></MediaElement>
</Grid>
Thanks in advance and have a great day!
There is an else missing. Your second if statement always resets the file to the first. Adding else should implement the desired toggling.
if (stage == 0)
{
TestElement.Source = new Uri("Stage12.mp4", UriKind.Relative);
TestElement.Play();
stage = 1;
}
//we need an else here, otherwise source is always "Stage12.mp4
else if (stage == 1)
{
TestElement.Source = new Uri("Stage8.mp4", UriKind.Relative);
TestElement.Play();
stage = 0;
}

C# & XAML how to get button to respond on first click

I actually got the bulk of my code to work. I appreciate the input, it pointed me in the correct direction. The problem I am having now is getting the buttons to work on the first click.
I appreciate any input that would help me improve my code.
Below are my XAML (MainPage.xaml) & C# (MainPage.xaml.cs) code.
<Page
x:Class="Calculator_Application.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Calculator_Application"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid>
<TextBlock x:Name="textBlock_title" TextWrapping="Wrap" Text="Calculator Application" VerticalAlignment="Top" Height="58" Width="252" Margin="86,30,0,0" SelectionChanged="textBlock_SelectionChanged" HorizontalAlignment="Left" FontSize="24" RenderTransformOrigin="-0.039,0.549" FontFamily="Calibri" Foreground="#FFBCB7B6"/>
<Button x:Name="button_info" Content="Information" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="135,561,0,0" Click="button_Click" FontFamily="Global User Interface" Foreground="#FFF05D5D"/>
<TextBox x:Name="textBox_number1" HorizontalAlignment="Left" Margin="29,191,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" TextChanged="textBox_number1_TextChanged"/>
<TextBox x:Name="textBox_number2" HorizontalAlignment="Left" Margin="29,387,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top"/>
<TextBlock x:Name="textBlock_info" HorizontalAlignment="Left" TextWrapping="Wrap" Text="Please input numbers to calculate:" VerticalAlignment="Top" Height="30" Width="252" FontSize="16" FontStyle="Italic" Margin="29,134,0,0" SelectionChanged="textBlock_info_SelectionChanged" Foreground="#FFE5957F"/>
<Button x:Name="button_add" Content="+" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="29,278,0,0" MinWidth="25" Height="20" FontSize="24" FontFamily="Global User Interface" Width="39" Background="Black"/>
<Button x:Name="button_subtract" Content="-" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="106,278,0,0" MinWidth="25" Height="20" FontSize="24" FontFamily="Global User Interface" Width="39"/>
<Button x:Name="button_multiply" Content="*" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="179,278,0,0" MinWidth="25" Height="20" FontSize="24" FontFamily="Global User Interface" Width="39"/>
<Button x:Name="button_divide" Content="/" HorizontalAlignment="Left" VerticalAlignment="Top" Margin="257,278,0,0" MinWidth="25" Height="20" FontSize="24" FontFamily="Global User Interface" Width="39"/>
<TextBlock x:Name="textBlock_equals" HorizontalAlignment="Left" TextWrapping="Wrap" Text="=" VerticalAlignment="Top" Height="39" Width="38" Margin="164,387,0,0" FontSize="36"/>
<TextBlock x:Name="textBlock_answer" HorizontalAlignment="Left" TextWrapping="Wrap" Text="answer" VerticalAlignment="Center" Height="23" Width="139" Margin="207,387,0,230" FontSize="22"/>
</Grid>
</Page>
Here is the C#
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
// Added to ensure popup is availible
using Windows.UI.Popups;
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=391641
namespace Calculator_Application
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
private double valHolder1 = 0;
private double valHolder2 = 0;
private double answer = 0;
public MainPage()
{
this.InitializeComponent();
this.NavigationCacheMode = NavigationCacheMode.Required;
}
/// <summary>
/// Invoked when this page is about to be displayed in a Frame.
/// </summary>
/// <param name="e">Event data that describes how this page was reached.
/// This parameter is typically used to configure the page.</param>
protected override void OnNavigatedTo(NavigationEventArgs e)
{
// TODO: Prepare page for display here.
// TODO: If your application contains multiple pages, ensure that you are
// handling the hardware Back button by registering for the
// Windows.Phone.UI.Input.HardwareButtons.BackPressed event.
// If you are using the NavigationHelper provided by some templates,
// this event is handled for you.
}
private void textBlock_SelectionChanged(object sender, RoutedEventArgs e)
{
}
private void textBlock_info_SelectionChanged(object sender, RoutedEventArgs e)
{
}
private async void button_Click(object sender, RoutedEventArgs e)
{
//Creating instance for the MessageDialog Class
//and passing the message in it's Constructor
MessageDialog msgbox = new MessageDialog("Page Lynn Potter, MBL 410, 05-15-2017, Robin Deitsch");
//Calling the Show method of MessageDialog class
//which will show the MessageBox
await msgbox.ShowAsync();
}
private void textBox_number1_TextChanged(object sender, TextChangedEventArgs e)
{
}
private void button_add_Click(object sender, RoutedEventArgs e)
{
//Make sure out text box has a value
if (textBox_number1.Text.Length != 0)
{
//Assign the value in text box to holder
valHolder1 = System.Double.Parse(textBox_number1.Text);
//Empty the text box
textBox_number1.Text = string.Empty;
if (textBox_number2.Text.Length != 0)
{
//Assign the value in text box to holder
valHolder2 = System.Double.Parse(textBox_number2.Text);
//Empty the text box
textBox_number2.Text = string.Empty;
}
}
else
{
//Calculate answer
answer = valHolder1 + valHolder2;
//Assign answer to text block
textBlock_answer.Text = answer.ToString();
}
}
private void button_subtract_Click(object sender, RoutedEventArgs e)
{
//Make sure out text box has a value
if (textBox_number1.Text.Length != 0)
{
//Assign the value in text box to holder
valHolder1 = System.Double.Parse(textBox_number1.Text);
//Empty the text box
textBox_number1.Text = string.Empty;
if (textBox_number2.Text.Length != 0)
{
//Assign the value in text box to holder
valHolder2 = System.Double.Parse(textBox_number2.Text);
//Empty the text box
textBox_number2.Text = string.Empty;
}
}
else
{
//Calculate answer
answer = valHolder1 - valHolder2;
//Assign answer to text block
textBlock_answer.Text = answer.ToString();
}
}
private void button_multiply_Click(object sender, RoutedEventArgs e)
{
//Make sure out text box has a value
if (textBox_number1.Text.Length != 0)
{
//Assign the value in text box to holder
valHolder1 = System.Double.Parse(textBox_number1.Text);
//Empty the text box
textBox_number1.Text = string.Empty;
if (textBox_number2.Text.Length != 0)
{
//Assign the value in text box to holder
valHolder2 = System.Double.Parse(textBox_number2.Text);
//Empty the text box
textBox_number2.Text = string.Empty;
}
}
else
{
//Calculate answer
answer = valHolder1 * valHolder2;
//Assign answer to text block
textBlock_answer.Text = answer.ToString();
}
}
private void button_divide_Click(object sender, RoutedEventArgs e)
{
//Make sure out text box has a value
if (textBox_number1.Text.Length != 0)
{
//Assign the value in text box to holder
valHolder1 = System.Double.Parse(textBox_number1.Text);
//Empty the text box
textBox_number1.Text = string.Empty;
if (textBox_number2.Text.Length != 0)
{
//Assign the value in text box to holder
valHolder2 = System.Double.Parse(textBox_number2.Text);
//Empty the text box
textBox_number2.Text = string.Empty;
}
}
else
{
//Calculate answer
answer = valHolder1 / valHolder2;
//Assign answer to text block
textBlock_answer.Text = answer.ToString();
}
}
}
}
You have an event handler configured for the button_info button.
<Button x:Name="button_info" Content="Information"
HorizontalAlignment="Left" VerticalAlignment="Top"
Margin="135,561,0,0"
FontFamily="Global User Interface" Foreground="#FFF05D5D"
Click="button_Click"/>
I don't see where you've configured handlers for the other buttons.
There should be something like this in the XAML.
<Button x:Name="button_add" Click = "button_add_Click" />
<Button x:Name="button_subtract" Click = "button_subtract_Click" />
<Button x:Name="button_multiply" Click = "button_multiply_Click" />
<Button x:Name="button_divide"Click = "button_divide_Click" />

Update TextBox content in WPF Window

I'm having a WPF Project, in which I'm performing an installation...
To show the installations progress, the window is containing a TextBox which I want to update using for example:
LogDisplay.AppendText("Initialising installation..." + "\r\n");
This works kind of...
The problem is that the content of the TextBox is only getting displayed when the installation is finished.
I have tried now several soluions, such as:
/*
LogDisplay.Update;
this.Update();
this.UpdateContent();
*/
But non of this was working for me...
The XAML code is:
<Window x:Class="Steam_Server_Installer.UI.ServerInstallation"
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:Steam_Server_Installer.UI"
mc:Ignorable="d"
Title="" Height="600" Width="900"
WindowStartupLocation="CenterScreen">
<Grid>
<TextBox x:Name="LogDisplay" HorizontalAlignment="Left" VerticalAlignment="Top" Height="470" Width="650" Margin="30,90,0,0" IsReadOnly="True"/>
<Button x:Name="cancel_button" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,530,115,0" Width="70" Content="Cancel" FontSize="16" Click="cancel_button_Click"/>
<Button x:Name="finish_start_button" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,530,25,0" Width="70" Content="Finish" FontSize="16" Click="finish_start_button_Click" IsEnabled="False"/>
</Grid>
</Window>
If someone could tell me a working solution or point me to another question, which already discusses this question, it would be very much appreciated.
Try using TextBlock rather than TextBox like this
<TextBlock x:Name="LogDisplay" HorizontalAlignment="Left" VerticalAlignment="Top" Height="470" Width="650" Margin="30,90,0,0" />
It would be better to use binding instead of setting it like this. First you will implement INotifyPropertyChanged in your .xaml.cs file like
public class YourClassName: Window, INotifyPropertyChanged
{
public event PropertyChangedEventHandler PropertyChanged;
protected void OnPropertyChanged(string propertyName)
{
if (PropertyChanged != null)
{
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
}
//then create a string variable in your .xaml.cs file like
private string _logText;
public string LogText
{
get{ return _logText;}
set { _logText = value; OnPropertyChanged("LogText"); }
}
public YourClassName()
{
InitializeComponent();
//setting data context of the window
this.DataContext = this;
}
}
And in your XAML, use:
<TextBlock Text="{Binding LogText, UpdateSourceTrigger=PropertyChanged}" HorizontalAlignment="Left" VerticalAlignment="Top" Height="470" Width="650" Margin="30,90,0,0" />
Now, you can just update LogText variable inside your class like
this.LogText = this.LogText + "Initialising installation..." + "\r\n"; //or better use StringBuilder and Append function
When use long task in UI thread, UI thread is not idle to update other content control.
You must use create other thread and handle task to thread then update the UI control by using the UI thread.
1.Create Thread or Task
2.Work task ...
3.Update the UI thread with Application.Current.Dispatcher.Invoke(() => { TextBox.Text = "text"; });
4.Finish

Telerik RadJumpList using DataVirtualizationMode.Automatic

I have a problem where im trying to use a Telerik Jump List with DataVirtualizationMode.Automatic, but i can't get it to work. The reason why i want to use this, is because i want my app to only download the data(games) which is in the current view of the Jump List control and not the whole data everytime. For example if i have searched for "Batman", and its returning 50 games, i don't want it to download and load all the games, only those i can see in the Jump List control.
Here is a sample of using DataVirtualizationMode.Automatic from Telerik, but i couldn't get it to work with my app: http://www.telerik.com/help/windows-phone/raddataboundlistbox-features-datavirtualization-automatic.html
Below is my Jump List control which i want to use with data virtualization.
MainPage.xaml:
<phone:PivotItem Header="Browse">
<Grid>
<telerikPrimitives:RadTextBox Name="txtSearch" HorizontalAlignment="Left" VerticalAlignment="Top" Height="80" Width="390"/>
<telerikPrimitives:RadImageButton Name="imgBtnSeachGame" VerticalAlignment="Top" HorizontalAlignment="Right" ButtonShape="Ellipse" BorderThickness="2" Margin="0,8,0,0" Click="imgBtnSeachGame_Click"></telerikPrimitives:RadImageButton>
<Controls:RadJumpList Name="jlGameList" ItemsSource="{Binding}" Tap="jlGameList_Tap" Margin="0,90,0,0" DataVirtualizationMode="Automatic">
<Controls:RadJumpList.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
<RowDefinition Height="20"></RowDefinition>
</Grid.RowDefinitions>
<Border Grid.Row="0" Background="{StaticResource PhoneAccentBrush}"
Padding="{StaticResource PhoneTouchTargetOverhang}"
Margin="0,0,0,0">
<TextBlock Name="tblGameTitle" Style="{StaticResource PhoneTextGroupHeaderStyle}" ManipulationStarted="tblGameTitle_ManipulationStarted" ManipulationCompleted="tblGameTitle_ManipulationCompleted">
<Run Text="{Binding GameTitle}"></Run>
</TextBlock>
</Border>
<Grid Background="#242424" Grid.Row="1">
<Image Name="imgGameList" Margin="0,0,0,0" Stretch="Fill" HorizontalAlignment="Left" VerticalAlignment="Top" Height="96" Width="96">
<Image.Source>
<BitmapImage UriSource="{Binding BoxArtFrontThumb}"
CreateOptions="BackgroundCreation" DecodePixelHeight="96" DecodePixelWidth="96" />
</Image.Source>
</Image>
<TextBlock Margin="110,0,0,0" Text="Platform" FontWeight="Bold" TextWrapping="Wrap" Foreground="YellowGreen" FontSize="{StaticResource PhoneFontSizeNormal}"/>
<TextBlock Name="txtPlatform" Margin="110,20,0,0" Text="{Binding Platform}"></TextBlock>
<TextBlock Text="Release Date" FontWeight="Bold" Margin="110,46,0,0" Foreground="YellowGreen" FontSize="{StaticResource PhoneFontSizeNormal}"/>
<TextBlock Name="txtReleaseDate" Margin="110,66,0,0" Text="{Binding ReleaseDate}"></TextBlock>
<!--</StackPanel>-->
</Grid>
<Grid Grid.Row="2"></Grid>
</Grid>
</DataTemplate>
</Controls:RadJumpList.ItemTemplate>
</Controls:RadJumpList>
</Grid>
</phone:PivotItem>
Below is where i bind my DataContext to my GetGamesListItems ObservableCollection in my GameData class. The imgBtnSearchGame_Click event method is being called when a user have typed for example "Batman" in my textbox txtSearch and tapped the button, it will then send the text to my GetGamesListData method.
MainPage.cs:
GameData gd = new GameData();
public MainPage()
{
InitializeComponent();
jlGameList.DataContext = gd.GetGamesListItems;
}
private void imgBtnSeachGame_Click(object sender, RoutedEventArgs e)
{
if (!string.IsNullOrEmpty(txtSearch.Text))
{
gd.GetGamesListData(txtSearch.Text, "", "");
}
}
Below is where i download the data in XML for the game name searched for. For example if it is "Batman" it will find and return all games with "Batman". The "BoxArtFrontThumb" Property is where im storing all the images for each game and is using async, because sometimes there can be quite alot of images it has to download and show.
GameData.cs
public void GetGamesListData(string name, string platform, string genre)
{
var webClient = new WebClient();
webClient.DownloadStringCompleted += GetGamesListRequestCompleted;
webClient.DownloadStringAsync(new Uri("http://thegamesdb.net/api/GetGamesList.php?name=" + name));
}
private async void GetGamesListRequestCompleted(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Error == null)
{
GetGamesListItems.Clear();
var feedXml = XDocument.Parse(e.Result);
var gameDataTasks = feedXml.Root.Descendants("Game").Select(
async x => new GetGamesList
{
ID = (int)x.Element("id"),
GameTitle = (string)x.Element("GameTitle"),
ReleaseDate = (string)x.Element("ReleaseDate") ?? "N/A",
Platform = (string)x.Element("Platform") ?? "N/A",
BoxArtFrontThumb = new Uri(await GetBoxArtFrontThumbAsync((int)x.Element("id")), UriKind.RelativeOrAbsolute),
}).ToList();
var gameData = await Task.WhenAll(gameDataTasks);
foreach (var item in gameData)
{
GetGamesListItems.Add(item);
}
}
}
Below is where its finding and storing the images for the games.
public async Task<string> GetBoxArtFrontThumbAsync(int id)
{
var client = new HttpClient();
var result = await client.GetStringAsync("http://thegamesdb.net/api/GetArt.php?id=" + id);
var feedXml = XDocument.Parse(result);
var gameData = feedXml.Root.Descendants("Images").Select(x => new GetArt
{
BoxArtFrontThumb = new Uri(GetBoxArtFrontThumb(x), UriKind.RelativeOrAbsolute),
}).ToList();
return gameData.Single().BoxArtFrontThumb.ToString();
}
private static string GetBoxArtFrontThumb(XElement gameNode)
{
string data = "http://thegamesdb.net/banners/" + (string)gameNode.Descendants("boxart")
.FirstOrDefault(b => (string)b.Attribute("side") == "front");
if (data == "http://thegamesdb.net/banners/")
{
data = "/NoImage.jpg";
}
return data;
}
I really hope i explained this well enough and hope that there is someone that can help me solve this problem. Thanks.
Although you are using JumpList, the mechanism for Virtualizing the data is the same as the DataBoundListBox. (You can find more information here in the DataBoundListBox docs. There is a good tutorial using an OData service.)
In order for the Automatic mode to work properly, you need to be using Telerik's VirtualizingDataCollection object and initialize it with the proper arguments (count and page size).
I don't see this in the code you have provided above, can you please open a support ticket so that I can investigate further? See my comment above for the link. Let me know the ticket number and I'll provide further assistance.

Display image from Uri in Winrt and MVVM Pattern

So I created an Windows Store app (aka Windows 8 Application / previously called Metro App) and I import a zip archive that contains image (the import work well).
When the zip is exctracted (in it's own folder), I add the object that represent the folder in an ObservableCollection.
This ObservableCollection is used as DataContext to a GridView, the name of the folder is properly displayed but the first image of the folder isn't... <= so that my problem.
I create my object using an static method after the extract is completed
public class ZipFolder
{
public string Title
{
get { return _title; }
set { _title = value;}
}
public int CurrentPage
{
get { return _currentPage; }
set { _currentPage = value;}
}
public Uri PathCover
{
get { return _pathCover; }
set { _pathCover = value;}
}
private string _title ;
private int _currentPage;
private Uri _pathCover;
}
public static async Task<ZipFolderObject> CreateComic(StorageFolder folder)
{
ZipFolderObject o = new ZipFolderObject();
o.Title = folder.DisplayName;
IReadOnlyList<StorageFile> asyncOperation = await folder.GetFilesAsync();
StorageFile cover = asyncOperation[0];
o.PathCover = new Uri("ms-appdata:///local/" + folder.Name + "/" + cover.Name);
return o;
}
And the binding look like this:
<DataTemplate x:Key="zipFolderItemTemplate">
<StackPanel Width="165" Height="250">
<Grid Height="215">
<Border Background="Bisque" Width="{Binding ActualWidth, ElementName=image}">
<!--<Image x:Name="image" VerticalAlignment="Top" HorizontalAlignment="Center" Source="{Binding Cover}" />-->
<Image Stretch="Uniform" x:Name="image" VerticalAlignment="Top" HorizontalAlignment="Center">
<Image.Source>
<BitmapImage UriSource="{Binding PathCover}" />
</Image.Source>
</Image>
</Border>
<Polygon Points="0,0 0,50, 50,0" Stroke="Red" FillRed" RenderTransformOrigin="0.5,0.5" Visibility="{Binding CurrentPage, Converter={StaticResource BookmarkVisibilityConverter}}" Width="{Binding ActualWidth, ElementName=image}" />
</Grid>
<TextBlock HorizontalAlignment="Center" TextWrapping="Wrap" VerticalAlignment="Top" Text="{Binding Title}" Margin="0,10,0,0" Foreground="Black" />
</StackPanel>
</DataTemplate>
So if anyone have the a hint to my problem it'll be great!
You can be use only directory/filename.ext on Image Source, if extracted images, sub directory.
Concat two value and set to PathCover Property:
folder.Name + "/" + cover.Name
And edit Data Templete in this section:
<Image Stretch="Uniform" x:Name="image" VerticalAlignment="Top" HorizontalAlignment="Center" Source={Binding PathCover}/>
Regards.
Simply use String instead of Uri.
in mainpage.xaml
<Image Source="{Binding VehicleIcon}" Height="54" Width="54"/>
in viewmodel.cs file
public String VehicleIcon {get;set; }
...
VehicleIcon = "ms-appx:///Assets/logo.png";

Categories