see, i have a html file and i'm trying to load other than iframe and web-browser controls
so i used RichTextBox is it supportable only with XAML? if it also supports HTML.how do i implement.
i tried to load a html file but it loaded as text.
below is my code.
<Grid x:Name="LayoutRoot" Background="White">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="400"/>
<ColumnDefinition Width="580"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition/>
</Grid.RowDefinitions>
<Canvas>
<TextBox Height="23" x:Name="txtFileName" Canvas.Left="15" Canvas.Top="40" Grid.Row="0" Grid.Column="0" Width="280" />
<Button Content="Browse" Height="23" HorizontalAlignment="Left" x:Name="btnBrowse" Canvas.Left="300" Canvas.Top="40" Grid.Row="0" Grid.Column="0" Width="75" Click="BtnBrowse_Click" />
<RichTextBox x:Name="rtxtboxHTML" Margin="3" Grid.Row="0" Grid.Column="1" Width="450" Height="400" HorizontalAlignment="Center" VerticalAlignment="Center" Canvas.Left="450" Canvas.Top="40" IsReadOnly="True" TextWrapping="Wrap"/>
</Canvas>
</Grid>
private void BtnBrowse_Click(object sender, RoutedEventArgs e)
{
OpenFileDialog openFileDialog = new OpenFileDialog();
openFileDialog.Filter = "Html files (*.html)|*.htm|All Files (*.*)|*.*";
if (openFileDialog.ShowDialog()==true)
{
txtFileName.Text = openFileDialog.File.Name;
FileInfo _File = openFileDialog.File;
using (StreamReader strReader = new StreamReader(openFileDialog.File.OpenRead()))
{
string _strTemp = string.Empty;
//var rs = Application.GetResourceStream(new Uri(openFileDialog.File.Name, UriKind.Relative));
//StreamReader sr = new StreamReader(rs.Stream);
while (!strReader.EndOfStream)
{
_strTemp = strReader.ReadToEnd();
}
strReader.Close();
rtxtboxHTML.Selection.Text = _strTemp;
}
}
}
where i went wrong...
Thank you
RichTextBox will not parse HTML for you.
Related
I am facing issues getting the string values using e.ClickedItem.
Here's how my ListView looks like:
<ListView
x:Name="PoemListView"
AutomationProperties.AutomationId="PoemListView"
AutomationProperties.Name="Poems In Item"
TabIndex="1"
ItemsSource="{Binding Item.Poems}"
IsItemClickEnabled="True"
ItemClick="PoemView_PoemClick"
SelectionMode="None"
SelectionChanged="PoemSelectionChanged"
IsSwipeEnabled="False" Padding="0,0,0,0" Margin="0,0,0,0"
ContinuumNavigationTransitionInfo.ExitElementContainer="True">
<ListView.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
</Grid.RowDefinitions>
<StackPanel Grid.Column="1" VerticalAlignment="Top" Margin="0,0,0,27.5" HorizontalAlignment="Left" ScrollViewer.VerticalScrollBarVisibility="Hidden">
<!--<CheckBox x:Name="PoemCheckbox" Checked="ContentChecked" Unchecked="ContentUnchecked"/>-->
<TextBlock x:Uid="PoemId" Name="PoemId" Text="{Binding PoemId}" DataContext="{Binding}" Style="{ThemeResource ListViewItemSubheaderTextBlockStyle}" TextWrapping="WrapWholeWords"/>
<TextBlock x:Uid="PoemTitleId" Text="{Binding PoemTitle}" FontSize="{Binding ElementName=FontSlider, Mode=OneWay, Path=Value}" DataContext="{Binding}" Style="{ThemeResource ListViewItemSubheaderTextBlockStyle}" Foreground="{ThemeResource PhoneMidBrush}" TextWrapping="WrapWholeWords"/>
<TextBlock x:Uid="PoemMeanId" Text="{Binding PoemMean}" DataContext="{Binding}" Style="{ThemeResource ListViewItemSubheaderTextBlockStyle}" TextWrapping="WrapWholeWords"/>
</StackPanel>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
This is the code behind the xaml page:
private void PoemView_PoemClick(object sender, ItemClickEventArgs e)
{
TextBlock PoemId = e.ClickedItem as TextBlock;
this.Frame.Navigate(typeof(Favorite), (e.ClickedItem as TextBlock));
On LoadState event of the Favorite page, I have added the below code:
private void NavigationHelper_LoadState(object sender, LoadStateEventArgs e)
{
string poem = e.NavigationParameter as string;
if (string.IsNullOrEmpty(poem))
{
FavText.Text = "no favorite text";
}
else { FavText.Text = poem;
}
}
The problem is in the LoadState while the e.NavigationParameter is loaded with the strings passed to it, the string poem is not loading properly. Therefore, the FavText.Text is always returning the "no favorite text".
Anyone has a clue on how to fix this?
Your PoemId is probably null when you cast e.ClickedItem as TextBlock
Try this
Poem poem = e.ClickedItem as Poem;
this.Frame.Navigate(typeof(Favorite), poem);
Instead of casting e.ClickedItem as TextBlock, I updated the code as below which worked perfectly fine:
var type = ((PoemItem)e.ClickedItem).PoemTitle;
this.Frame.Navigate(typeof(Favorite), type);
I have parsed RSS feed http://www.teluguone.com/videosongs/videoSongsXml.php?cat_id=6.
And displayed songpics in Horizontal List view. As shown below
When I click on a particular song it was playing in the space above.
But,here I want to get default video along with Horizontal list view.And when I click on a particular video it should be played.
How to get the default video along with List view.
XAML code:
<phone:PhoneApplicationPage
x:Class="PhoneApp1.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:delay="clr-namespace:Delay;assembly=PhonePerformance"
mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="768"
FontFamily="{StaticResource PhoneFontFamilyNormal}"
FontSize="{StaticResource PhoneFontSizeNormal}"
Foreground="{StaticResource PhoneForegroundBrush}"
SupportedOrientations="Portrait" Orientation="Portrait"
shell:SystemTray.IsVisible="True" Loaded="PhoneApplicationPage_Loaded">
<!--LayoutRoot is the root grid where all page content is placed-->
<Grid x:Name="LayoutRoot" Background="Transparent">
<Grid.RowDefinitions>
<RowDefinition Height="Auto"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<!--TitlePanel contains the name of the application and page title-->
<StackPanel x:Name="TitlePanel" Grid.Row="0" Margin="12,17,0,28">
<TextBlock x:Name="ApplicationTitle" Text="Teluguone" Style="{StaticResource PhoneTextNormalStyle}"/>
<TextBlock x:Name="PageTitle" Text="Songs" Margin="9,-7,0,0" Style="{StaticResource PhoneTextTitle1Style}"/>
</StackPanel>
<!--ContentPanel - place additional content here-->
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<MediaElement x:Name="player" AutoPlay="True" Margin="0,0,0,282"/>
<ScrollViewer HorizontalScrollBarVisibility="Hidden" Height="Auto" Margin="-60,411,-93,10" >
<ListBox x:Name="videosongList" ScrollViewer.HorizontalScrollBarVisibility="Auto"
ScrollViewer.VerticalScrollBarVisibility="Disabled" Height="200" Width="1000" SelectionChanged="videosongList_SelectionChanged" >
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Margin="0,50,0,0" Orientation="Horizontal">
<Image x:Name="img1" Source="{Binding songpic}" ></Image>
<TextBlock Text="{Binding songname}" TextWrapping="NoWrap" VerticalAlignment="Bottom"
FontSize="20" />
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
<ListBox.ItemsPanel >
<ItemsPanelTemplate>
<StackPanel Orientation="Horizontal"></StackPanel>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
</ScrollViewer>
</Grid>
</Grid>
Code for XAML.cs:
namespace PhoneApp1
{
public partial class MainPage : PhoneApplicationPage
{
public MainPage()
{
InitializeComponent();
}
private void PhoneApplicationPage_Loaded(object sender, RoutedEventArgs e)
{
// is there network connection available
if (!System.Net.NetworkInformation.NetworkInterface.GetIsNetworkAvailable())
{
MessageBox.Show("No network connection available!");
return;
}
// start loading XML-data
WebClient downloader = new WebClient();
Uri uri = new Uri("http://www.teluguone.com/videosongs/videoSongsXml.php?cat_id=6", UriKind.Absolute);
downloader.DownloadStringCompleted += new DownloadStringCompletedEventHandler(VideosongsDownloaded);
downloader.DownloadStringAsync(uri);
}
void VideosongsDownloaded(object sender, DownloadStringCompletedEventArgs e)
{
if (e.Result == null || e.Error != null)
{
MessageBox.Show("There was an error downloading the XML-file!");
}
else
{
// Deserialize if download succeeds
XDocument document = XDocument.Parse(e.Result);
XmlSerializer serializer = new XmlSerializer(typeof(videosongs));
videosongs videosongs = (videosongs)serializer.Deserialize(document.CreateReader());
videosongList.ItemsSource = videosongs.Collection;
}
}
private async void videosongList_SelectionChanged(object sender, SelectionChangedEventArgs e)
{
Songsdetails song = (Songsdetails)videosongList.SelectedItem;
var url = await YouTube.GetVideoUriAsync(song.songcode, YouTubeQuality.Quality480P);
player.Source = url.Uri;
}
}
}
Anybody please give me any suggestion of getting default video playing along with horizontal list view.
Many Thanks.
Did you try playing Youtube videos using the Youtube class from Codeplex.
Youtube Class
or else you could refer the sample from msdn:
Youtube Video sample
I tried this How to: Filter Data in a View so i tried this approach but it didn't work for me because windows phone 8 environment couldn't find 'ListCollectionView'.
My collection is following.
//My observableCollection
ObservableCollection<ClonedWrapper> dsForProgress = new ObservableCollection<ClonedWrapper >();
//My Function which shows at first time.
private async Task CloudImages()
{
IsolatedStorageFile isf = IsolatedStorageFile.GetUserStoreForApplication();
try
{
List<MainWrapper> serverdata = new List<MainWrappe>();
serverdata = await ImageUrlAsync();//This function is returning the Deserialize object of images
if (serverdata.Count != 0)
{
foreach (var imgInfo in serverdata)
{
string folderPath = "Fagbokforlaget/Books/" + BookInfo.Id.Trim();
ClonedWrapper item = new ClonedWrapper()
{
//Name, Cover, Info, Title, IsEnableButton, IsVisibleButton,
// IsVisible are the assigned keys to the xaml page
Id = imgInfo.Id,
Name = imgInfo.Name,
Cover = await GetCoverImage(imgInfo),
Info = imgInfo.Info,
Title = imgInfo.Title,
Url = imgInfo.Url,
IsEnableButton = "True",
IsVisible = "Collapsed",
Date = Convert.ToDateTime(imgInfo.Date)
};
if (isf.DirectoryExists(folderPath))
{
item.ButtonStatus = "Read";
item.IsVisibleBookDeleteButton = "Visible";
}
else
{
item.ButtonStatus = "Download";
item.IsVisibleBookDeleteButton = "Collapsed";
}
dsForProgress.Add(item);
}
}
else
{
MessageBox.Show("You have no any downloaded books!");
}
listCloudImages.ItemsSource = dsForProgress;
}
catch (Exception exe)//I am getting exception here on extreme first run in absense of internet.
{
MessageBox.Show(exe.Message);
}
}
//My xaml page is following. It is the default page that loaded at first time. you can say it is the face of the application. User download the images. and buttonStatus convert into the Read button. so now what i am doing i will keep two buttons in appliationbar one cloud second downloaded. ON Download button click i want to show only downloaded images.
<ListBox Name="listCloudImages" Visibility="Visible" Grid.Row="1" ScrollViewer.VerticalScrollBarVisibility="Auto" FontFamily="Segoe UI" FontStyle="Normal" FontWeight="Thin" Margin="0,0,0,50">
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<tools:WrapPanel Orientation="Horizontal">
</tools:WrapPanel>
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
<ListBox.ItemContainerStyle>
<Style TargetType="ListBoxItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch"></Setter>
</Style>
</ListBox.ItemContainerStyle>
<ListBox.ItemTemplate>
<DataTemplate>
<Border BorderThickness="1" Background="#151414" CornerRadius="3" Margin="3" Width="150" TextOptions.DisplayColorEmoji="True" BorderBrush="#1c1b1b">
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal">
<Image x:Name="imgBookImage" Source="{Binding Cover}" Visibility="Visible" VerticalAlignment="Top" HorizontalAlignment="Center"
Width="80" Height="100" ImageOpened="imgBookImage_ImageOpened"/>
<StackPanel Orientation="Horizontal">
<TextBlock Visibility="{Binding IsVisible}" Text="{Binding ProgressPercentage}" FontFamily="Segoe UI" FontSize="18" FontWeight="ExtraBold" Foreground="White" Margin="5,0"></TextBlock>
</StackPanel>
</StackPanel>
<StackPanel Orientation="Vertical">
<TextBlock Text="{Binding Title}" FontFamily="Segoe UI" FontSize="13.5"
Foreground="White" TextTrimming="WordEllipsis"
VerticalAlignment="Top" HorizontalAlignment="Left"
TextWrapping="Wrap"
Width="300" Padding="2"/>
<TextBlock Text="{Binding Info}" FontSize="13.5" FontFamily="Segoe UI"
Foreground="White"
VerticalAlignment="Top" HorizontalAlignment="Left"
TextWrapping="Wrap"
Width="300" Padding="2"/>
<ProgressBar x:Name="downloadProgressBar" Foreground="Green" IsIndeterminate="True" VerticalAlignment="Center" Width="120" TextOptions.TextHintingMode="Animated" Visibility="{Binding IsVisible}" CharacterSpacing="2"/>
<Button Content="{Binding ButtonStatus}" x:Name="btnDownload" IsEnabled="{Binding IsEnableButton, Converter={StaticResource ButtonVisibilityIsEnableConverter}}"
Click="btnDownload_Click" Tag="{Binding}" Width="120" BorderThickness="1" FontSize="13.5" Margin="0,5"
FontFamily="Segoe UI" tools:SlideInEffect.LineIndex="2" HorizontalAlignment="Left" VerticalAlignment="Top"
Foreground="White">
</Button>
<Image x:Name="imgCancelImage" Source="/Assets/Tiles/CancelImage.png" Visibility="{Binding IsVisible}" VerticalAlignment="Center" Margin="97,-66,0,0"
Tap="imgCancelImage_Tap" HorizontalAlignment="Right" Width="25" Height="25" Tag="{Binding}"/>
<Button x:Name="btnDeleteImage" Click="btnDeleteImage_Click"
Tag="{Binding}" BorderThickness="1" Margin="97,-66,0,0"
Height="55" Width="55"
Visibility="{Binding ButtonStatus, Converter={StaticResource DeleteButtonVisibilityConverter}}">
<Button.Background>
<ImageBrush ImageSource="/Images/delete.png" Stretch="Fill"></ImageBrush>
</Button.Background>
</Button>
</StackPanel>
</StackPanel>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Based on your code, you can do something quite easy, if you wanna show only downloaded books try this:
private void ApplicationBarButtonShowAllDownLoaded(object sender, EventArgs e)
{
var c = (Application.Current as App).dsForProgress.Where(x => x.ButtonStatus.Equals("Download"));
listCloudImages.ItemsSource = c;
}
be sure that ObservableCollection<ClonedWrapper> dsForProgress is public
In your book model, you can pass a bool property IsDownload and when you download books you set this property to true.For your filter, just use linQ for take all books download or no dowload like this :
var noDownloadedBooks =
from b in yourObservableCollection
where b.IsDownload == false
select b;
var downloadedBooks =
from b in yourObservableCollection
where b.IsDownload == true
select b;
What you need to do is use a CollectionViewSource, this can point to your original collection and it can handle filtering!
Scott Hanselman has a great example blog post about it here... http://www.hanselman.com/blog/CollectionViewSourceIsCrazyUsefulForBindingToFilteredObservableCollectionsOnWindowsPhone8.aspx
I am having some problems getting my app to display images from the web.
It workes fine in my sample data as can be seen:
But one the app runs on the emulate do i get this, you can see the link in the textbox:
This is my code, what am I doing wrong?
<phone:LongListSelector.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal" Margin="12,2,0,4" Height="105" Width="432">
<!--Replace rectangle with image-->
<Image>
<Image.Source>
<BitmapImage UriSource="{Binding Image}" CreateOptions="BackgroundCreation"/>
</Image.Source>
</Image>
<StackPanel Width="311" Margin="8,-7,0,0">
<TextBlock Text="{Binding Name}" TextWrapping="Wrap" Margin="10,0" Style="{StaticResource PhoneTextExtraLargeStyle}" FontSize="{StaticResource PhoneFontSizeLarge}" />
<TextBox Text="{Binding Image}" FontSize="10" />
</StackPanel>
</StackPanel>
</DataTemplate>
</phone:LongListSelector.ItemTemplate>
The only reason you can see your images is that your code fails to download them.
I just created a simple app for windows phone to download images manually (just to see what exactly is going on?).
The code is pretty straightforward:
XAML:
<Grid x:Name="ContentPanel" Grid.Row="1" Margin="12,0,12,0">
<StackPanel>
<Image>
<Image.Source>
<BitmapImage UriSource="{Binding Image}" CreateOptions="BackgroundCreation"/>
</Image.Source>
</Image>
<Button Content="go" Click="ClickMe"/>
</StackPanel>
</Grid>
And the code-behinde:
private void ClickMe(object sender, RoutedEventArgs e)
{
//var url = "http://img7.anidb.net/pics/anime/136529.jpg";
var url = "http://img7.anidb.net/pics/anime/54893.jpg";
HttpWebRequest req = (HttpWebRequest)HttpWebRequest.Create(url);
//req.ContentType = "image/jpeg";
//req.Accept = "image/jpeg";
req.Method = "GET";
req.BeginGetResponse(Callback, req);
}
private void Callback(IAsyncResult result)
{
try
{
HttpWebRequest httpReq = (HttpWebRequest)result.AsyncState;
HttpWebResponse response = (HttpWebResponse)httpReq.EndGetResponse(result);
Stream myStream = response.GetResponseStream();
Deployment.Current.Dispatcher.BeginInvoke(() =>
{
BitmapImage bmp = new BitmapImage();
bmp.SetSource(myStream);
var character = new Character();
character.Image = bmp;
ContentPanel.DataContext = character;
//image1.Source = bmp;
});
}
catch (Exception ex)
{
MessageBox.Show(ex.Message);
}
}
When I'm trying to download the image on WP I recive a webException with Stats code: System.Net.HttpStatusCode.Forbidden
BTW - sometimes I get this error when I'm trying to get the image using web browser. Not so often, but it happens. Most probably that website does not allow to get images.
How can i get access to longlistselector items.
My XAML is:
<Grid x:Name="ContentPanel" Grid.Row="1" HorizontalAlignment="Left" Height="Auto" Margin="30,20,0,0" Grid.RowSpan="2" VerticalAlignment="Top" Width="420">
<phone:LongListSelector Name="longList" HorizontalAlignment="Left" Height="Auto" Margin="0" VerticalAlignment="Top" Width="420">
<phone:LongListSelector.ItemTemplate>
<DataTemplate>
<Grid Background="Transparent">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="210" />
<ColumnDefinition Width="210" />
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="160" />
</Grid.RowDefinitions>
<Image Name="first" Width="210" Margin="0" Source="{Binding ImageName}" Grid.Column="1" VerticalAlignment="Top" HorizontalAlignment="Left" />
<Image Name="second" Width="210" Margin="0" Source="{Binding ImageName}" Grid.Column="2" VerticalAlignment="Top" HorizontalAlignment="Right" />
</Grid>
</DataTemplate>
</phone:LongListSelector.ItemTemplate>
</phone:LongListSelector>
</Grid>
I want to get access of image objects first & second
I need to assign source of these two image objects from list of class which contain ImageName string as variable(holds path of jpg image) consecutive and then next two to next row and so on..
Add a new folder to the solution and rename the folder to "Model"
Then add a new class with the name "ImageSourceClass"
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace TestApp.Model
{
public class ImageSourceClass
{
public string ImageUrl { get; set; }
public ImageSourceClass(string imageUrl)
{
this.ImageUrl = imageUrl;
}
}
public class ImageData : ObservableCollection<ImageSourceClass>
{
public ImageData()
{
Add(new ImageSourceClass("/Assets/Images/Fruits.jpg"));
Add(new ImageSourceClass("/Assets/Images/Beignets.jpg"));
Add(new ImageSourceClass("/Assets/Images/Dessert.jpg"));
Add(new ImageSourceClass("/Assets/Images/Pretzel.jpg"));
Add(new ImageSourceClass("/Assets/Images/Shrimp.jpg"));
Add(new ImageSourceClass("/Assets/Images/SteakSandwich.jpg"));
}
}
}
MainPage.xaml
Added the below namespace to MainPage.xaml
Note : [According to your solution name namespace may vary]
xmlns:MyModel="clr-namespace:TestApp.Model"
<Grid x:Name="LayoutRoot" Background="Transparent" >
<Grid.Resources>
<MyModel:ImageData x:Key="imageDatasource"></MyModel:ImageData>
</Grid.Resources>
<phone:LongListSelector x:Name="lstRestoItems" ItemsSource="{StaticResource imageDatasource}" LayoutMode="List">
<phone:LongListSelector.ItemTemplate>
<DataTemplate>
<Image Source="{Binding ImageUrl}" Height="100" Width="100" HorizontalAlignment="Left"></Image>
</DataTemplate>
</phone:LongListSelector.ItemTemplate>
</phone:LongListSelector>
</Grid>
We are done , now just clean and re-build your application and press f5