New frame display exception after ListView SelectionChange method uwp c# - c#

There is a ContestListView with elements:
public MainPage()
{
this.InitializeComponent();
List<int> list = new List<int>();
list.Add(2);
list.Add(3);
list.Add(5);
list.Add(7);
ContestListView.ItemsSource = list;
}
I want to navigate to another Frame when SelectionChange is.
private void ContestSelectionChange(object sender, SelectionChangedEventArgs e)
{
this.Frame.Navigate(typeof(BlankPage1));
}
But I have a problem - sometimes, when I choose element at list, the BlankPage1 starts load, but I got an unhandled exception
{"Unspecified error\r\n\r\nUnspecified error\r\n"}
at this place
#if DEBUG && !DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION
UnhandledException += (sender, e) =>
{
if (global::System.Diagnostics.Debugger.IsAttached) global::System.Diagnostics.Debugger.Break();
};
#endif
This exception can be after first SelectionChandeg, but it can be too after second, third etc.
There is BlankPage1 XAML:
<Page
x:Class="Contests.BlankPage1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Contests"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Page.TopAppBar>
<CommandBar Foreground="White">
<CommandBar.Background>
<ImageBrush Stretch="Fill" ImageSource="Assets/app02_0013_panel_main.png"/>
</CommandBar.Background>
<CommandBar.SecondaryCommands>
<AppBarButton Label="LogOut" Click="onClick"/>
</CommandBar.SecondaryCommands>
</CommandBar>
</Page.TopAppBar>
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<ScrollViewer>
<RelativePanel>
<TextBlock x:Name="txtContestName"
Text="TestTest "
Foreground="DarkOliveGreen"
RelativePanel.AlignLeftWithPanel="True"
RelativePanel.Below=""
TextWrapping="Wrap"
FontSize="20"
Margin="5,10,0,10"/>
<TextBlock x:Name="CategoryExpiration" FontSize="12"
RelativePanel.AlignLeftWithPanel="True"
RelativePanel.Below="txtContestName"
Margin="5,0,0,10">
<Run x:Name="txtCategory" Text="Test "/>
<Run x:Name="txtExpiration" Text="2016-05-23" Foreground="Green"/>
</TextBlock>
<RelativePanel x:Name="QuestionPanel" RelativePanel.Below="CategoryExpiration"
RelativePanel.AlignLeftWithPanel="True"
RelativePanel.AlignRightWithPanel="True"
Background="Green"
Margin="5,0,5,5">
<TextBlock x:Name="textblock1" Text="Question:" Foreground="White"
RelativePanel.AlignLeftWithPanel="True"
Margin="5,5,5,0"/>
<TextBlock x:Name="txtQuestion" Foreground="White"
Text="Test?"
RelativePanel.AlignHorizontalCenterWithPanel="True"
RelativePanel.Below="textblock1"
TextWrapping="Wrap"
Margin="10, 5" TextAlignment="Center"/>
<TextBox x:Name="AnswerText" PlaceholderText="Test"
RelativePanel.Below="txtQuestion"
RelativePanel.AlignRightWithPanel="True"
RelativePanel.AlignLeftWithPanel="True"
Margin="5,5"/>
<Button x:Name="bSendAnswer" Content="Test"
RelativePanel.Below="AnswerText"
RelativePanel.AlignHorizontalCenterWithPanel="True"
Foreground="White"
Margin="5,5" Width="335"/>
</RelativePanel>
<RelativePanel x:Name="OrgPanel" RelativePanel.Below="QuestionPanel"
RelativePanel.AlignLeftWithPanel="True"
RelativePanel.AlignRightWithPanel="True"
Margin="5,0,5,5" BorderBrush="Gray">
<TextBlock x:Name="textblock2" Text="Organizator" Foreground="Green"
RelativePanel.AlignLeftWithPanel="True"
Margin="5,5,5,0"/>
<TextBlock x:Name="Org" Text="Test"
RelativePanel.Below="textblock2"
Foreground="DarkGreen"
FontSize="12"
RelativePanel.AlignRightWithPanel="True"
RelativePanel.AlignLeftWithPanel="True"
Margin="5,5"/>
</RelativePanel>
<RelativePanel x:Name="DesriptionPanel" RelativePanel.Below="OrgPanel"
RelativePanel.AlignLeftWithPanel="True"
RelativePanel.AlignRightWithPanel="True"
Margin="5,0,5,5" BorderBrush="Gray">
<TextBlock x:Name="textblock3" Text="Opis konkursu" Foreground="Green"
RelativePanel.AlignLeftWithPanel="True"
Margin="5,5,5,0"/>
<TextBlock x:Name="txtDescription" Text="test"
RelativePanel.Below="textblock3"
TextWrapping="Wrap"
Foreground="DarkGreen"
FontSize="12"
RelativePanel.AlignRightWithPanel="True"
RelativePanel.AlignLeftWithPanel="True"
Margin="5,5"/>
</RelativePanel>
<RelativePanel x:Name="PrizePanel" RelativePanel.Below="DesriptionPanel"
RelativePanel.AlignLeftWithPanel="True"
RelativePanel.AlignRightWithPanel="True"
Margin="5,0,5,5" BorderBrush="Gray">
<TextBlock x:Name="textblock4" Text="Test" Foreground="Green"
RelativePanel.AlignLeftWithPanel="True"
Margin="5,5,5,0"/>
<TextBlock x:Name="txtPrize" Text=""
RelativePanel.Below="textblock4"
Foreground="DarkGreen"
TextWrapping="Wrap"
FontSize="12"
RelativePanel.AlignRightWithPanel="True"
RelativePanel.AlignLeftWithPanel="True"
Margin="5,5"/>
</RelativePanel>
</RelativePanel>
</ScrollViewer>
</Grid>
What my problem is?

Related

How to set Textbox value on click command

On my Resources.xaml(Resource Dictionary) I have a DataTemplate :
<DataTemplate x:Key="ProductDetailsContentTemplate">
<StackPanel Orientation="Vertical" >
<Viewbox Margin="27,0,28,0" Height="200" >
<Image UWPUtil:ImageExtensions.CachedUriSource="{Binding ImageUri}" />
</Viewbox>
<TextBlock Text="Description" Style="{StaticResource CaptionTextBlockStyle}" FontWeight="Bold" FontSize="24"/>
<TextBlock Text="{Binding ProductDescription}" Style="{StaticResource SubtitleTextBlockStyle}" FontSize="30"/>
<TextBlock Text="Barcode" Style="{StaticResource CaptionTextBlockStyle}" FontWeight="Bold" FontSize="24"/>
<TextBlock Text="{Binding Barcode}" Style="{StaticResource SubtitleTextBlockStyle}" FontSize="30"/>
<TextBlock Text="Weight" Style="{StaticResource CaptionTextBlockStyle}" FontWeight="Bold" FontSize="24"/>
<TextBlock Text="{Binding Weight}" Style="{StaticResource SubtitleTextBlockStyle}" FontSize="30"/>
<TextBlock Text="Quantity" Style="{StaticResource CaptionTextBlockStyle}" FontWeight="Bold" FontSize="24"/>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="25*"/>
<ColumnDefinition Width="50*"/>
<ColumnDefinition Width="25*"/>
</Grid.ColumnDefinitions>
<Button x:Name="SubtractQytyButton" Grid.Column="0" Content="-" FontSize="24" HorizontalAlignment="Stretch"
Margin="5,0" Style="{StaticResource TestButtonStyle}" FontWeight="ExtraBold"
Click="SubQytyButton_Click"/>
<TextBox x:Name="QuantityTextBox" Grid.Column="1" HorizontalAlignment="Stretch" FontSize="24" Margin="5,0"
KeyDown="Quantity_Keydown" TextChanging="Quantity_TextChanging"
Text="{Binding Quantity, Mode=TwoWay, Converter={StaticResource DecmialConverter}}" MaxLength="5" TextAlignment="Center"/>
<Button x:Name="AddQytyButton" Grid.Column="2" Content="+" FontSize="24" HorizontalAlignment="Stretch"
Margin="5,0" Style="{StaticResource TestButtonStyle}" FontWeight="ExtraBold"
Click="AddQytyButton_Click"/>
</Grid>
</StackPanel>
</DataTemplate><br>
I file nested it using the File Nesting from Mads Kristensen , here is the thread: https://marketplace.visualstudio.com/items?itemName=MadsKristensen.FileNesting
so I have a Resources.xaml.cs on my ResourceDictionary
my problem is I want to set my QuantityTextBox Value on AddQytyButton and SubQytyButton click command, here is my click command event:
private void AddQytyButton_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
//does not exist in the current context
QuantityTextBox.Text = "test";
}
OR
private void AddQytyButton_Click(object sender, Windows.UI.Xaml.RoutedEventArgs e)
{
Button btn = sender as Button;
// this is not working as null reference
var textbox = (btn.Parent as StackPanel).Children[1] as TextBox;
}
Thanks,
NicoTing
You should cast btn.Parent to a Grid instead of a StackPanel since you are using the former in your XAML.
var textbox = (btn.Parent as Grid).Children[1] as TextBox;

Programmaticallly generate grids in Stack Panel (C# UWP)

I have code to download data from WordPress
Here it is:
private async void Down_at_Start() {
RestAPI rest = new RestAPI("http://simplegames.com.ua/wp-json/wc/v1/", "ck_9d64c027d2c5f81b8bed3342eeccc6d337be813d", "cs_60697b1e6cbdeb8d62d19e0765e339f8e3334754");
WCObject wc = new WCObject(rest);
//Get all products
var orders = await wc.GetOrders();
string date = orders[0].date_created + "+0:00";
DateTime dt = DateTime.Parse(date);
string convertedDate = dt.ToString("dd/MM/yyyy HH:mm:ss");
try
{
date1.Text = convertedDate;
adress1.Text = orders[0].shipping.address_1.ToString() + " " + orders[0].shipping.address_2;
name1.Text = orders[0].billing.first_name.ToString();
}
catch (Exception e)
{
Debug.WriteLine(e.Message);
Debug.WriteLine(e.StackTrace);
}
string date_2 = orders[1].date_created + "+0:00";
DateTime dt2 = DateTime.Parse(date_2);
string convertedDate2 = dt2.ToString("dd/MM/yyyy HH:mm:ss");
try
{
date2.Text = convertedDate2;
adress2.Text = orders[1].shipping.address_1.ToString() + " " + orders[1].shipping.address_2;
name2.Text = orders[1].billing.first_name.ToString();
}
catch (Exception e)
{
Debug.WriteLine(e.Message);
Debug.WriteLine(e.StackTrace);
}
string date_3 = orders[2].date_created + "+0:00";
DateTime dt3 = DateTime.Parse(date_3);
string convertedDate3 = dt3.ToString("dd/MM/yyyy HH:mm:ss");
try
{
date3.Text = convertedDate3;
adress3.Text = orders[2].shipping.address_1.ToString() + " " + orders[2].shipping.address_2;
name3.Text = orders[2].billing.first_name.ToString();
}
catch (Exception e)
{
Debug.WriteLine(e.Message);
Debug.WriteLine(e.StackTrace);
}
string date_4 = orders[3].date_created + "+0:00";
DateTime dt4 = DateTime.Parse(date_4);
string convertedDate4 = dt4.ToString("dd/MM/yyyy HH:mm:ss");
try
{
date4.Text = convertedDate4;
adress4.Text = orders[3].shipping.address_1.ToString() + " " + orders[3].shipping.address_2;
name4.Text = orders[3].billing.first_name.ToString();
}
catch (Exception e)
{
Debug.WriteLine(e.Message);
Debug.WriteLine(e.StackTrace);
}
string date_5 = orders[4].date_created + "+0:00";
DateTime dt5 = DateTime.Parse(date_5);
string convertedDate5 = dt5.ToString("dd/MM/yyyy HH:mm:ss");
try
{
date5.Text = convertedDate5;
adress5.Text = orders[4].shipping.address_1.ToString() + " " + orders[4].shipping.address_2;
name5.Text = orders[4].billing.first_name.ToString();
}
catch (Exception e)
{
Debug.WriteLine(e.Message);
Debug.WriteLine(e.StackTrace);
}
}
As you see I have static number of fields.
My XAML:
<Page
x:Class="Milano.InWork"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:Milano"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid BorderBrush="White" BorderThickness="1">
<Grid.Background>
<ImageBrush Stretch="Fill" ImageSource="Images/Background.png"/>
</Grid.Background>
<Grid HorizontalAlignment="Left" Height="720" VerticalAlignment="Top" Width="60" BorderBrush="#FFF5F1F1" BorderThickness="0,0,1,0">
<Button x:Name="MenuButton" Content="" HorizontalAlignment="Left" Margin="10,10,0,0" VerticalAlignment="Top" Height="38" Width="38">
<Button.Background>
<ImageBrush Stretch="Uniform" ImageSource="Images/Menu-100.png"/>
</Button.Background>
</Button>
<Button x:Name="logoutbutton" Content="" HorizontalAlignment="Left" Margin="10,650,0,0" VerticalAlignment="Top" Height="43" Width="38">
<Button.Background>
<ImageBrush Stretch="Uniform" ImageSource="Images/Logout_Button.png"/>
</Button.Background>
</Button>
</Grid>
<Grid HorizontalAlignment="Left" Height="47" Margin="63,2,-121,0" VerticalAlignment="Top" Width="1338" BorderBrush="#FFFDFDFD" Padding="0,0,0,1" BorderThickness="0,0,0,1">
<TextBlock x:Name="textBlock" HorizontalAlignment="Left" TextWrapping="Wrap" Text="В Работе" VerticalAlignment="Top" Height="37" Width="1218" FontSize="32" FontFamily="SF UI Display" Padding="550,0,0,0" Foreground="White"/>
</Grid>
<ScrollViewer HorizontalAlignment="Left" Height="668" Margin="63,52,0,0" VerticalAlignment="Top" Width="350">
<StackPanel Height="1020" Width="350" BorderBrush="#FFFDFCFC" BorderThickness="0,0,1,0">
<Grid Height="204" BorderBrush="#FFFBF8F8" BorderThickness="0,0,0,1">
<TextBlock x:Name="date1" HorizontalAlignment="Left" TextAlignment="Center" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="350" Height="50" FontFamily="SF UI Display" FontSize="30" FontWeight="Light" Foreground="White" />
<TextBlock x:Name="adress1" TextAlignment="Center" HorizontalAlignment="Left" Margin="0,146,-1,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Height="58" Width="350" FontFamily="SF UI Display" FontSize="20" FontWeight="Light" Foreground="White" />
<TextBlock x:Name="name1" HorizontalAlignment="Left" TextAlignment="Center" Margin="0,86,-1,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Height="60" Width="350" FontFamily="SF UI Display" FontSize="30" FontWeight="Light" Foreground="White" Padding="0,0,0,0"/>
</Grid>
<Grid Height="204" BorderBrush="#FFFBF8F8" BorderThickness="0,0,0,1">
<TextBlock x:Name="date2" TextAlignment="Center" HorizontalAlignment="Left" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="350" Height="50" Foreground="White" FontFamily="SF UI Display" FontSize="30" FontWeight="Light" />
<TextBlock x:Name="adress2" TextAlignment="Center" HorizontalAlignment="Left" Margin="0,145,-1,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Height="59" Width="350" FontFamily="SF UI Display" FontSize="20" FontWeight="Light" Foreground="White" />
<TextBlock x:Name="name2" HorizontalAlignment="Left" Margin="0,87,-1,0" TextAlignment="Center" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Height="64" Width="350" FontFamily="SF UI Display" FontSize="30" FontWeight="Light" Foreground="White" Padding="0,0,0,50"/>
</Grid>
<Grid Height="204" BorderBrush="#FFFBF8F8" BorderThickness="0,0,0,1">
<TextBlock x:Name="date3" HorizontalAlignment="Left" TextAlignment="Center" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="350" Height="50" Foreground="White" FontFamily="SF UI Display" FontSize="30" FontWeight="Light" />
<TextBlock x:Name="adress3" HorizontalAlignment="Left" TextAlignment="Center" Margin="0,143,0,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Width="350" Height="61" FontFamily="SF UI Display" FontSize="20" FontWeight="Light" Foreground="White" />
<TextBlock x:Name="name3" HorizontalAlignment="Left" TextAlignment="Center" Margin="0,86,-1,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Height="60" Width="350" FontFamily="SF UI Display" FontSize="30" FontWeight="Light" Foreground="White" Padding="0,0,0,50"/>
</Grid>
<Grid Height="204" BorderBrush="#FFFBF8F8" BorderThickness="0,0,0,1">
<TextBlock x:Name="date4" HorizontalAlignment="Left" TextWrapping="Wrap" TextAlignment="Center" Text="" VerticalAlignment="Top" Width="350" Height="50" Foreground="White" FontFamily="SF UI Display" FontSize="30" FontWeight="Light" />
<TextBlock x:Name="adress4" HorizontalAlignment="Left" Margin="0,153,0,0" TextWrapping="Wrap" TextAlignment="Center" Text="TextBlock" VerticalAlignment="Top" Height="61" Width="342" FontFamily="SF UI Display" FontSize="20" FontWeight="Light" Foreground="White" />
<TextBlock x:Name="name4" HorizontalAlignment="Left" TextAlignment="Center" Margin="0,86,-1,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Height="60" Width="350" FontFamily="SF UI Display" FontSize="30" FontWeight="Light" Foreground="White" Padding="0,0,0,50"/>
</Grid>
<Grid Height="204" BorderBrush="#FFFBF8F8" BorderThickness="0,0,0,1">
<TextBlock x:Name="date5" HorizontalAlignment="Left" TextWrapping="Wrap" Text="" VerticalAlignment="Top" TextAlignment="Center" Width="350" Height="50" Foreground="White" FontFamily="SF UI Display" FontSize="30" FontWeight="Light" />
<TextBlock x:Name="adress5" TextAlignment="Center" HorizontalAlignment="Left" Margin="0,155,0,0" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top" Height="49" Width="349" FontFamily="SF UI Display" FontSize="20" FontWeight="Light" Foreground="White" />
<TextBlock x:Name="name5" HorizontalAlignment="Left" TextAlignment="Center" Margin="0,86,-1,0" TextWrapping="Wrap" Text="" VerticalAlignment="Top" Height="60" Width="350" FontFamily="SF UI Display" FontSize="30" FontWeight="Light" Foreground="White" Padding="0,0,0,50"/>
</Grid>
</StackPanel>
</ScrollViewer>
</Grid>
How I can count how many orders in answer from website and generate grids?
Thank's for help so much! :)

Mahapps : ScrollViewer update list on event KeyDown in WPF ( C # )

I have a problem I can not solve.
As you can see in the picture , there is a label , a textobx and a ScrollViewer .
Now , I have to update the ScrollViewer when the user searches through the textbox .
Part of an event every time you make a keydown .
So if I write Statut ... should put first in the file list with the names "statuto rai"
the list can have N elements
Image list:
Xaml code:
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="25"></RowDefinition>
<RowDefinition Height="25"></RowDefinition>
<RowDefinition Height="*"></RowDefinition>
</Grid.RowDefinitions>
<Grid Grid.Row="0" Background="GhostWhite"/>
<Grid Grid.Row="1" Background="Gray"/>
<TextBlock HorizontalAlignment="Center" VerticalAlignment="Center">Documenti allegati</TextBlock>
<Border Grid.Row="1" Margin="3" BorderBrush="White" Height="22" Background="#fff">
<TextBox BorderBrush="#465E76" KeyDown="TextBox_KeyDown" BorderThickness="0" FontSize="10" Background="#fff" Foreground="#565656" controls:TextBoxHelper.Watermark="Ricerca Locale" FontFamily="{StaticResource Lato Thin}" HorizontalContentAlignment="Center" ></TextBox>
</Border>
<ScrollViewer Grid.Row="2" VerticalScrollBarVisibility="Hidden" PanningMode="Both" Name="scrollDocuments">
<ItemsControl ItemsSource="{Binding Path=attachmentsList}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<StackPanel Grid.Column="0" Grid.Row="0">
<Button Grid.ColumnSpan="2">
<Button.Template>
<ControlTemplate TargetType="{x:Type Button}">
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="450"></ColumnDefinition>
</Grid.ColumnDefinitions>
<Grid.RowDefinitions>
<RowDefinition Height="60"/>
</Grid.RowDefinitions>
<Grid Grid.Row="0" Background="#fff"></Grid>
<TextBlock Foreground="#565656" FontFamily="{StaticResource Lato Semibold}" Grid.Row="0" Grid.Column="0" HorizontalAlignment="Left" VerticalAlignment="Center" FontSize="10" Margin="10,3,0,0" Style="{DynamicResource Lato-Semibold}" Text="{Binding contList}"/>
<Image Source="/Resources/Images/icon-document-browser.png" HorizontalAlignment="Left" Margin="22,-12,0,0" Width="22"/>
<TextBlock Foreground="#565656" FontFamily="{StaticResource Lato Semibold}" Grid.Row="0" Grid.Column="0" HorizontalAlignment="Left" VerticalAlignment="Center" FontSize="10" Margin="21,32,0,0" Style="{DynamicResource Lato-Semibold}" Text="{Binding FileSizeConverted}"/>
<TextBlock Foreground="#565656" FontFamily="{StaticResource Lato Semibold}" Grid.Row="0" Grid.Column="0" HorizontalAlignment="Left" VerticalAlignment="Center" FontSize="12" Margin="55,-10,0,0" Style="{DynamicResource Lato-Semibold}" Text="{Binding Name}"/>
<TextBlock Foreground="#565656" FontFamily="{StaticResource Lato Semibold}" Grid.Row="0" Grid.Column="0" HorizontalAlignment="Right" VerticalAlignment="Center" FontSize="12" Margin="55,-10,10,0" Style="{DynamicResource Lato-Semibold}" Text="{Binding ModifiedDate}"/>
<TextBlock Foreground="#565656" FontFamily="{StaticResource Lato Semibold}" Grid.Row="0" Grid.Column="0" HorizontalAlignment="Right" VerticalAlignment="Center" FontSize="10" Margin="55,25,10,0" FontWeight="Bold" Style="{DynamicResource Lato-Semibold}" Text="Nessuna copia locale"/>
<Border Grid.Row="0" Grid.ColumnSpan="2" BorderBrush="#DDD" BorderThickness="0,0,0,1"></Border>
</Grid>
</ControlTemplate>
</Button.Template>
</Button>
</StackPanel>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</ScrollViewer>
<Viewbox Grid.Row="2" Name="testoNessunAllegato" Visibility="Collapsed" Margin="20">
<TextBlock Text="Nessun allegato disponibile."></TextBlock>
</Viewbox>
</Grid>
CodeBehind event code:
private void TextBox_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
{
string find = ((TextBox)sender).Text;
attachmentsList = attachmentsList.Where(x => x.Name == find).ToList();
InitializeComponent();
}
in practice I do the intelligiente research, so every time I insert a letter filtrale list , and print it again , of course real time .
I hope I explained myself .
Thank you
I see you use bindings, in this case there is a much better stuff to reach your goal. It's CollectionView.
Here is a simple app for you which more or less fullfill your requirements:
View
<StackPanel Orientation="Horizontal">
<Label Content="Search" />
<TextBox MinWidth="30" Text="{Binding FilterText, UpdateSourceTrigger=PropertyChanged}" />
</StackPanel>
<ListBox ItemsSource="{Binding Data}" />
UpdateSorceTrigger=PropertyChanges updates FilterText in ViewModel every time when you press any key.
Data is a ICollectionView
ViewModel
public ICollectionView Data { get; private set; }
...
// Create default view for the list
Data = CollectionViewSource.GetDefaultView(list);
// Set filter delegate for CollectionView
Data.Filter = FilterData;
....
private bool FilterData(object obj)
{
DataContainer cont = (DataContainer)obj;
return string.IsNullOrEmpty(FilterText) || cont.Name.StartsWith(FilterText, StringComparison.OrdinalIgnoreCase);
}
private string myfiltertext;
public string FilterText
{
get { return myfiltertext; }
set
{
myfiltertext = value;
// Refresh collection view after Filter text modification
Data.Refresh();
}
}

Resize grid after rotation Windows phone 8.1

[![enter image description here][1]][1]I have problem with panel size in ListView. I have StackPanel in GridView and after rotation i want resize this gridview to the whole page, but after rotate stackPanel had the same widht as he had in portrait mode. Here is my code.
But when I start application on Landscape mode it is all ok and grid is resized.
<Page
x:Class="KlientWP.VypisZakazek"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:KlientWP"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d" Loaded="Page_Loaded" SizeChanged="Page_SizeChanged">
<Page.Background>
<SolidColorBrush Color="{ThemeResource PhoneImagePlaceholderColor}"/>
</Page.Background>
<Grid x:Name="ContentRoot" Margin="0,9.5,0,0">
<ScrollViewer>
<Pivot Title="Přehled databáze" HorizontalAlignment="Stretch" Margin="0,0,0,0">
<PivotItem Header="Zakázky" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="10,0,20,10" >
<ListView SelectionMode="None" x:Name="ListBox1" Margin="0,0,-0.167,0.167"
HorizontalAlignment="Stretch"
ItemsSource="{Binding}" >
<ListView.ItemTemplate>
<DataTemplate>
<Grid x:Name="grdTsk" Opacity="1" Margin="0,0,0,10" Width="1500" HorizontalAlignment="Stretch" Background="#FF302E2E" ManipulationMode="All" Tapped="grdTsk_Tapped" >
<Grid.RowDefinitions>
<RowDefinition Height="20"/>
<RowDefinition Height="30"/>
</Grid.RowDefinitions>
<FlyoutBase.AttachedFlyout>
<MenuFlyout>
<MenuFlyoutItem Text="Detail zakázky" Click="Detail" />
</MenuFlyout>
</FlyoutBase.AttachedFlyout>
<TextBlock Grid.Row="1" Text="{Binding nazev1}" Width="1500" FontSize="22" TextWrapping="Wrap" HorizontalAlignment="Stretch" Margin="5,0,0,0" Visibility="Visible" FontWeight="Light" Foreground="White"/>
<!--<StackPanel>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Stretch" Margin="0,0,0,0" >
<TextBlock Text="{Binding nazev}" FontSize="22" TextWrapping="Wrap" Margin="5,0,0,0" Visibility="Visible" FontWeight="Light" Foreground="White"/>
</StackPanel>
<StackPanel Orientation="Horizontal" Margin="0,0,0,0">
<TextBlock x:Name="predmetTb" Text="{Binding zakazka}" FontSize="18" Margin="5,0,0,0" TextWrapping="Wrap" />
<TextBlock Text="{Binding kod_firmy}" FontSize="18" TextWrapping="Wrap" Margin="15,0,0,0" Foreground="#FFFFF413" />
</StackPanel>
</StackPanel>-->
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</PivotItem>
</Pivot>
</ScrollViewer>
</Grid>
binding:
CultureInfo culture = new CultureInfo("cs-CZ");
DataContractJsonSerializer ser = new DataContractJsonSerializer(typeof(List<dataInfo>));
MemoryStream stream = new MemoryStream(Encoding.UTF8.GetBytes(json));
var obj = (List<dataInfo>)ser.ReadObject(stream);
List<dataInfo> VypisZakazekli = new List<dataInfo>();
VypisZakazekli.Clear();
foreach (dataInfo di in obj)
{
string iZakazka = "ID: " + di.zakazka;
string sNazev = di.nazev;
string sKod = "Firma: " + di.kod_firmy;
string sStatus = "Status: " + di.status_v;
string sDruh = di.druh_zakazky;
VypisZakazekli.Add(new dataInfo(iZakazka, sNazev, sKod, sStatus, sDruh));
}
this.ListBox1.ItemsSource = VypisZakazekli;
}
Try to add this to your listview :
<ListView.ItemContainerStyle>
<Style TargetType="ListViewItem">
<Setter Property="HorizontalContentAlignment" Value="Stretch" />
</Style>
</ListView.ItemContainerStyle>

textbox text not becoming empty on button command

I have a button with binding as ClearCommand which clears the value of text box but it is not working.
public SellerDetailsViewModel() //constructor
{
sdObject = new SellerDetailsTable();
_SaveCommand = new RelayCommand(Save, CanSave);
_ClearCommand = new RelayCommand(clear, Canclear);
}
private readonly ICommand _ClearCommand;
public ICommand ClearCommand { get { return _ClearCommand; } }
public event PropertyChangedEventHandler PropertyChanged;
public void onPropertyChange(string propertyName)
{
if (PropertyChanged != null)
PropertyChanged(this, new PropertyChangedEventArgs(propertyName));
}
public bool Canclear(object obj)
{
return true;
}
public void clear(object obj)
{
this.PancardNumber = "";
this.ContactNumber = 0;
this.FirstName = "";
this.LastName = "";
this.MiddleName = "";
this.OtherDocument = "";
this.Address = "";
}
<Page x:Class="CarDealer.SellerDetails"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
mc:Ignorable="d"
d:DesignHeight="800" d:DesignWidth="900"
xmlns:ViewModels="clr-namespace:CarDealer.PresentationLayer.ViewModel"
Title="SellerDetails">
<Page.Resources>
<ViewModels:SellerDetailsViewModel x:Key="ViewModel">
</ViewModels:SellerDetailsViewModel>
<ControlTemplate x:Key="TextBoxErrorTemplate">
<DockPanel LastChildFill="True">
<TextBlock DockPanel.Dock="Bottom" Foreground="Red" FontSize="10pt"
Text="{Binding ElementName=MyAdorner,Path=AdornedElement.(Validation.Errors)[0].ErrorContent}"/>
<Border BorderBrush="Red" BorderThickness="2" Width="225" Height="35" >
<AdornedElementPlaceholder Name="MyAdorner" />
</Border>
</DockPanel>
</ControlTemplate>
</Page.Resources>
<Grid DataContext="{Binding Source={StaticResource ViewModel}}">
<Label Content="Seller Details" Height="39" HorizontalAlignment="Left" Margin="27,25,0,0" Name="lblTitle" VerticalAlignment="Top" FontSize="22" FontWeight="Bold" FontFamily="Times New Roman" Foreground="#FF1313D8" Width="169" />
<Label Content="First Name" Height="28" HorizontalAlignment="Left" Margin="44,87,0,0" Name="lblCustName" VerticalAlignment="Top" FontSize="16" />
<Label Content="Address" FontSize="16" Height="28" HorizontalAlignment="Left" Margin="461,253,0,0" Name="lblAdress" VerticalAlignment="Top" />
<Label Content="Pan Card Number" FontSize="16" Height="28" HorizontalAlignment="Left" Margin="44,243,0,0" Name="lblPanCardNumber" VerticalAlignment="Top" />
<Label Content="Contact Number" FontSize="16" Height="28" HorizontalAlignment="Left" Margin="44,320,0,0" Name="lblContactNumber" VerticalAlignment="Top" />
<Label Content="Handover Date" FontSize="16" Height="28" HorizontalAlignment="Left" Margin="461,170,0,0" Name="label1" VerticalAlignment="Top" />
<Label Content="Other Document" FontSize="16" Height="28" HorizontalAlignment="Left" Margin="44,399,0,0" Name="label2" VerticalAlignment="Top" />
<Button Content="Save" Height="37" Command="{Binding SaveCommand}" HorizontalAlignment="Left" Margin="299,543,0,0" Name="btnSave" VerticalAlignment="Top" Width="131" FontSize="22" />
<TextBox Height="33" Text="{Binding FirstName, Mode=TwoWay}" HorizontalAlignment="Left" Margin="205,92,0,0" Name="txtFirstName" VerticalAlignment="Top" Width="225" BorderThickness="2" FontSize="16" />
<Label Content="Last Name" FontSize="16" Height="28" HorizontalAlignment="Left" Margin="44,165,0,0" Name="label3" VerticalAlignment="Top" />
<TextBox BorderThickness="2" Text="{Binding LastName, Mode=TwoWay}" Height="33" HorizontalAlignment="Left" Margin="205,170,0,0" Name="txtLastName" VerticalAlignment="Top" Width="225" FontSize="16" />
<TextBox BorderThickness="2" Text="{Binding PancardNumber, Mode=TwoWay}" Height="33" HorizontalAlignment="Left" Margin="205,248,0,0" Name="txtPanCard" VerticalAlignment="Top" Width="225" FontSize="16" />
<TextBox BorderThickness="2" Height="33" HorizontalAlignment="Left" Margin="205,325,0,0" Validation.ErrorTemplate="{StaticResource TextBoxErrorTemplate}" Name="txtcontactNumber" VerticalAlignment="Top" Width="225" FontSize="16">
<TextBox.Text>
<Binding Path="ContactNumber">
<Binding.ValidationRules>
<ExceptionValidationRule/>
</Binding.ValidationRules>
</Binding>
</TextBox.Text>
</TextBox>
<TextBox Height="126" Text="{Binding Address, Mode=TwoWay}" HorizontalAlignment="Left" Margin="627,248,0,0" Name="TxtAddress" VerticalAlignment="Top" Width="257" BorderThickness="2" FontSize="16" VerticalScrollBarVisibility="Visible" />
<TextBox BorderThickness="2" Text="{Binding OtherDocument, Mode=TwoWay}" Height="126" HorizontalAlignment="Left" Margin="205,399,0,0" Name="rchTxtOtherDoc" VerticalAlignment="Top" Width="257" FontSize="16" VerticalScrollBarVisibility="Visible" />
<DatePicker Height="33" Text="{Binding HandoverDate}" HorizontalAlignment="Left" Margin="627,170,0,0" Name="dtPickerHandoverDate" VerticalAlignment="Top" Width="225" FontSize="16" />
<Button Content="Clear All" Command="{Binding ClearCommand}" FontSize="22" Height="37" HorizontalAlignment="Left" Margin="500,543,0,0" Name="btnClearAll" VerticalAlignment="Top" Width="131" />
<Label Content="Middle Name" FontSize="16" Height="28" HorizontalAlignment="Left" Margin="471,87,0,0" Name="label4" VerticalAlignment="Top" />
<TextBox BorderThickness="2" Text="{Binding MiddleName, Mode=TwoWay}" FontSize="16" Height="33" HorizontalAlignment="Left" Margin="627,87,0,0" Name="txtMiddleName" VerticalAlignment="Top" Width="225" />
</Grid>
I have debugged the code execution. clear function is executed but in the view, the textbox is not empty. Can you help me figure out what I am doing wrong?
I have added remaining code please what is missing.
You should post the rest of your xaml. Assuming your controls are TextBox's...
public void clear(object obj)
{
this.PancardNumber.Text = "";
this.ContactNumber.Text = "0"; //depends what this control is
this.FirstName.Text = "";
this.LastName.Text = "";
this.MiddleName.Text = "";
this.OtherDocument.Text = "";
this.Address.Text = "";
}
Try this, hope it helps.
public void clear(object obj)
{
this.PancardNumber = "";
this.ContactNumber = 0;
this.FirstName = "";
this.LastName = "";
this.MiddleName = "";
this.OtherDocument = "";
this.Address = "";
// should work on other document
OnPropertyChanged("OtherDocument");
}
<Button Content="Clear All" Command="{Binding ClearCommand}" FontSize="22" Height="37" HorizontalAlignment="Left" Margin="500,543,0,0" Name="btnClearAll" VerticalAlignment="Top" Width="131" />
<TextBox BorderThickness="2" Text="{Binding OtherDocument, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" Height="126" HorizontalAlignment="Left" Margin="205,399,0,0" Name="rchTxtOtherDoc" VerticalAlignment="Top" Width="257" FontSize="16" VerticalScrollBarVisibility="Visible" />

Categories

Resources