trying to get an image from image array to span over two buttons that I have set up in a 5x5 grid. Based on a randomly generated 2D grid, images are placed in places on the button grid. If a position in the array = 2 then a 2 square long image is to be placed and the same for r = 3.
//This is if button (1,1) is pressed
private void _1_1_Click(object sender, RoutedEventArgs e)
{
if (radar.IsChecked == true)
{
if (gridarray[0,0] == 1)
{
Random rnd = new Random();
int r = rnd.Next(0,3);
_1_1.Content = images[r];
streak.Content = streakn++;
}
if (gridarray[0,0] == 2 || gridarray[0,1] == 2)
{
Random rnd = new Random();
int r = rnd.Next(3, 5);
_1_1.Content = images[r];
streak.Content = streakn++;
}
if (gridarray[0,0] == 3 || gridarray[0,1] == 3 || gridarray[0,2] == 3)
{
Random rnd = new Random();
int r = rnd.Next(5, 7);
_1_1.Content = images[r];
streak.Content = streakn++;
}
}
// here is where the image array is defined
private void defineImages()
{
images[0].Source = new BitmapImage(new Uri("Resources/small1.png", UriKind.Relative));
images[1].Source = new BitmapImage(new Uri("Resources/small2.jpg", UriKind.Relative));
images[2].Source = new BitmapImage(new Uri("Resources/small3.png", UriKind.Relative));
images[3].Source = new BitmapImage(new Uri("Resources/medium-1.jpg", UriKind.Relative));
images[4].Source = new BitmapImage(new Uri("Resources/medium2.jpg", UriKind.Relative));
images[5].Source = new BitmapImage(new Uri("Resources/large1.png", UriKind.Relative));
images[6].Source = new BitmapImage(new Uri("Resources/large2.jpg", UriKind.Relative));
}
// This is some relevant xaml
<TextBlock Grid.Row="0" Grid.Column="0" Margin="5" FontSize="15">Fish Caught:</TextBlock>
<TextBlock Grid.Row="1" Grid.Column="0" Margin="5" FontSize="15">Guess Streak:</TextBlock>
<TextBlock Grid.Row="2" Grid.Column="0" Margin="5" FontSize="15">Fish in Water:</TextBlock>
<Label Grid.Row="0" Grid.Column="1" Margin="5" FontSize="20" x:Name="caught"></Label>
<Label Grid.Row="1" Grid.Column="1" Margin="5" FontSize="20" x:Name="streak"></Label>
<Label Grid.Row="2" Grid.Column="1" Margin="5" FontSize="20" x:Name="fishinwater"></Label>
<Label Grid.Row="0" Grid.Column="2" Content="Timer:" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="25"/>
<Label Grid.Column="3" Grid.ColumnSpan="2" Grid.Row="0" Content="Tool Select:" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="25"/>
<RadioButton x:Name="rod" Grid.Row="1" Grid.Column="3" Content="Rod" Grid.RowSpan="2" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="30"/>
<RadioButton x:Name="radar" Grid.Row="1" Grid.Column="4" Content="Radar" Grid.RowSpan="2" HorizontalAlignment="Center" VerticalAlignment="Center" FontSize="30"/>
<Button x:Name="_1_1" Grid.Row="3" Grid.Column="0" Background="White" Click="_1_1_Click">
<Image x:Name="_1"/>
</Button>
<Button x:Name="_1_2" Grid.Row="3" Grid.Column="1" Background="White">
<Image x:Name="_1_2image"/>
</Button>
<Button x:Name="_1_3" Grid.Row="3" Grid.Column="2" Background="White">
<Image x:Name="_1_3image"/>
</Button>
<Button x:Name="_1_4" Grid.Row="3" Grid.Column="3" Background="White">
<Image x:Name="_1_4image"/>
</Button>
<Button x:Name="_1_5" Grid.Row="3" Grid.Column="4" Background="White">
<Image x:Name="_1_5image"/>
</Button>
<Button x:Name="_2_1" Grid.Row="4" Grid.Column="0" Background="White">
<Image x:Name="_2_1image"/>
</Button>
<Button x:Name="_2_2" Grid.Row="4" Grid.Column="1" Background="White">
<Image x:Name="_2_2image"/>
</Button>
<Button x:Name="_2_3" Grid.Row="4" Grid.Column="2" Background="White">
<Image x:Name="_2_3image"/>
</Button>
<Button x:Name="_2_4" Grid.Row="4" Grid.Column="3" Background="White">
<Image x:Name="_2_4image"/>
</Button>
<Button x:Name="_2_5" Grid.Row="4" Grid.Column="4" Background="White">
<Image x:Name="_2_5image"/>
</Button>
<Button x:Name="_3_1" Grid.Row="5" Grid.Column="0" Background="White">
<Image x:Name="_3_1image"/>
</Button>
<Button x:Name="_3_2" Grid.Row="5" Grid.Column="1" Background="White">
<Image x:Name="_3_2image"/>
</Button>
<Button x:Name="_3_3" Grid.Row="5" Grid.Column="2" Background="White">
<Image x:Name="_3_3image"/>
</Button>
<Button x:Name="_3_4" Grid.Row="5" Grid.Column="3" Background="White">
<Image x:Name="_3_4image"/>
</Button>
<Button x:Name="_3_5" Grid.Row="5" Grid.Column="4" Background="White">
<Image x:Name="_3_5image"/>
</Button>
<Button x:Name="_4_1" Grid.Row="6" Grid.Column="0" Background="White">
<Image x:Name="_4_1image"/>
</Button>
<Button x:Name="_4_2" Grid.Row="6" Grid.Column="1" Background="White">
<Image x:Name="_4_2image"/>
</Button>
<Button x:Name="_4_3" Grid.Row="6" Grid.Column="2" Background="White">
<Image x:Name="_4_3image"/>
</Button>
<Button x:Name="_4_4" Grid.Row="6" Grid.Column="3" Background="White">
<Image x:Name="_4_4image"/>
</Button>
<Button x:Name="_4_5" Grid.Row="6" Grid.Column="4" Background="White">
<Image x:Name="_4_5image"/>
</Button>
<Button x:Name="_5_1" Grid.Row="7" Grid.Column="0" Background="White">
<Image x:Name="_5_1image"/>
</Button>
<Button x:Name="_5_2" Grid.Row="7" Grid.Column="1" Background="White">
<Image x:Name="_5_2image"/>
</Button>
<Button x:Name="_5_3" Grid.Row="7" Grid.Column="2" Background="White">
<Image x:Name="_5_3image"/>
</Button>
<Button x:Name="_5_4" Grid.Row="7" Grid.Column="3" Background="White">
<Image x:Name="_5_4image"/>
</Button>
<Button x:Name="_5_5" Grid.Row="7" Grid.Column="4" Background="White">
<Image x:Name="_5_5image"/>
</Button>
<Label x:Name="timer" FontSize="30" Grid.RowSpan="2" Grid.Row="1" Grid.Column="2" Margin="5" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Content="0"/>
Ignore the image tags they are not in use images are going directly into buttons.
Related
So I am created a window with a space to display and show each form, depending on which button click, the issue is I cant seem to find any solution on how to have the form open in the specific window or in the panel of that specific window.
Is this even possible?
My Window design code is as follow:
Title="winHomeDash" Height="650" Width="950"
WindowStartupLocation="CenterScreen"
WindowStyle="None"
AllowsTransparency="True"
materialDesign:ThemeAssist.Theme="Dark"
Background="{x:Null}" Loaded="BtnMenuShort_Click">
<materialDesign:Card UniformCornerRadius="15" Margin="25" Width="900" Height="600" Background="{DynamicResource ResourceKey=MaterialDesignDarkBackground}">
<materialDesign:Card UniformCornerRadius="15" HorizontalAlignment="Left" Width="225" Background="#0A1828">
<DockPanel Width="225" Height="600">
<StackPanel Height="155" VerticalAlignment="Top" Width="225">
<Image Height="50" Width="50" Margin="0 15 0 15" Source="/UserPic.png"/>
<Label Name="lblName" BorderThickness="0" FontFamily="Arial" FontWeight="Bold" FontSize="17" Margin="0 0 0 5" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Foreground="#FF2372FA" Height="24" Loaded="Window_Loaded"/>
<Label x:Name="lblDateTime" Content="" FontFamily="Arial" FontWeight="SemiBold" FontSize="12" HorizontalContentAlignment="Center" VerticalContentAlignment="Center" Foreground="#FF2372FA" Margin="0 0 0 18" Height="22" Width="225" Loaded="LblDateTime_Loaded"/>
<Rectangle Name="rec1" Height="7" Fill="#FF2372FA"/>
</StackPanel>
<materialDesign:Card Name="card2" Width="210" UniformCornerRadius="15" Height="445" Background="{DynamicResource ResourceKey=MaterialDesignDarkBackground}" Foreground="White" Margin="-210,155,0,0">
<StackPanel VerticalAlignment="Center" Height="445" Name="stpnlMenu">
<Button x:Name="btnCollapse" Width="15" Height="30" BorderBrush="{x:Null}" Foreground="{x:Null}" FlowDirection="RightToLeft" Margin="195,207.5,0,0" Click="BtnMenuShort_Click">
<Button.Background>
<ImageBrush ImageSource="/more_than_25px.png"/>
</Button.Background>
</Button>
<Button x:Name="btnMenu" Content="MENU" HorizontalContentAlignment="Left" Width="160" Height="20" Margin="0,-227.5,0,0" FontFamily="Arial" FontSize="10" FontWeight="SemiBold" Background="{x:Null}" BorderBrush="{x:Null}" Click="BtnMenuShort_Click" VerticalAlignment="Top" Cursor="Hand" Tag="tagMenu"/>
<Button x:Name="btnHome" Content="HOME" HorizontalContentAlignment="Left" Width="160" Height="20" Margin="0,-187.5,0,0" FontFamily="Arial" FontSize="10" FontWeight="SemiBold" Background="{x:Null}" BorderBrush="{x:Null}" VerticalAlignment="Top" Cursor="Hand" Tag="tagMenu"/>
<Button x:Name="btnFuel" Content="FUEL" HorizontalContentAlignment="Left" Width="160" Height="20" Margin="0,-147.5,0,0" FontFamily="Arial" FontSize="10" FontWeight="SemiBold" Background="{x:Null}" BorderBrush="{x:Null}" RenderTransformOrigin="-0.836,17.714" VerticalAlignment="Top" Cursor="Hand" Tag="tagMenu" Click="BtnFuel_Click"/>
<Button x:Name="btnTyres" Content="TYRES" HorizontalContentAlignment="Left" Width="160" Height="20" Margin="0,-122.5,0,0" FontFamily="Arial" FontSize="10" FontWeight="SemiBold" Background="{x:Null}" BorderBrush="{x:Null}" RenderTransformOrigin="-0.836,17.714" VerticalAlignment="Top" Cursor="Hand" Tag="tagMenu"/>
<Button x:Name="btnService" Content="SERVICE" HorizontalContentAlignment="Left" Width="160" Height="20" Margin="0,-97.5,0,0" FontFamily="Arial" FontSize="10" FontWeight="SemiBold" Background="{x:Null}" BorderBrush="{x:Null}" RenderTransformOrigin="-0.836,17.714" VerticalAlignment="Top" Cursor="Hand" Tag="tagMenu"/>
<Button x:Name="btnBags" Content="WASTE BAGS" HorizontalContentAlignment="Left" Width="160" Height="20" Margin="0,-72.5,0,0" FontFamily="Arial" FontSize="10" FontWeight="SemiBold" Background="{x:Null}" BorderBrush="{x:Null}" RenderTransformOrigin="-0.836,17.714" VerticalAlignment="Top" Cursor="Hand" Tag="tagMenu"/>
<Button x:Name="btnExpand" Width="15" Height="30" BorderBrush="{x:Null}" Foreground="{x:Null}" FlowDirection="LeftToRight" Margin="25,-30,0,0" Click="BtnMenuShort_Click" Visibility="Hidden">
<Button.Background>
<ImageBrush ImageSource="/more_than_25px.png"/>
</Button.Background>
</Button>
<Button x:Name="btnChat" Content="QUICK CHAT" HorizontalContentAlignment="Left" Width="160" Height="20" Margin="0,122.5,0,0" FontFamily="Arial" FontSize="10" FontWeight="SemiBold" Background="{x:Null}" BorderBrush="{x:Null}" RenderTransformOrigin="-0.836,17.714" VerticalAlignment="Top" Cursor="Hand" Tag="tagMenu"/>
<Button x:Name="btnHelp" Content="SUPPORT" HorizontalContentAlignment="Left" Width="160" Height="20" Margin="0,5,0,0" FontFamily="Arial" FontSize="10" FontWeight="SemiBold" Background="{x:Null}" BorderBrush="{x:Null}" RenderTransformOrigin="-0.836,17.714" VerticalAlignment="Top" Cursor="Hand" Tag="tagMenu"/>
<Button x:Name="btnLogOut" Content="LOG OUT" HorizontalContentAlignment="Left" Width="160" Height="20" Margin="0,5,0,20" FontFamily="Arial" FontSize="10" FontWeight="SemiBold" Background="{x:Null}" BorderBrush="{x:Null}" RenderTransformOrigin="-0.836,17.714" Click="BtnLogOut_Click" VerticalAlignment="Top" Cursor="Hand" Tag="tagMenu"/>
</StackPanel>
</materialDesign:Card>
<StackPanel Width="30" Height="445" Margin="-400,155,0,0" Background="#0A1828">
<Rectangle Name="rec2" Height="10"/>
<Button Name="btnMenuShort" BorderBrush="{x:Null}" Foreground="{x:Null}" Height="20" Click="BtnMenuShort_Click" Cursor="Hand">
<Button.Background>
<ImageBrush ImageSource="/menu_30px.png" Stretch="Uniform"/>
</Button.Background>
</Button>
<Rectangle Name="rec3" Height="20"/>
<Button Name="btnHomeShort" BorderBrush="{x:Null}" Foreground="{x:Null}" Height="20" Width="20" Cursor="Hand">
<Button.Background>
<ImageBrush ImageSource="/home_30px.png" Stretch="Fill"/>
</Button.Background>
</Button>
<Rectangle Name="rec4" Height="20"/>
<Button Name="btnFuelShort" BorderBrush="{x:Null}" Foreground="{x:Null}" Height="20" Width="20" Margin="0,0,0,5" Cursor="Hand" Click="BtnFuel_Click">
<Button.Background>
<ImageBrush ImageSource="/gas_station_30px.png" Stretch="Fill"/>
</Button.Background>
</Button>
<Button Name="btnTyresShort" BorderBrush="{x:Null}" Foreground="{x:Null}" Height="20" Width="20" Margin="0,0,0,5" Cursor="Hand">
<Button.Background>
<ImageBrush ImageSource="/wheel_30px.png" Stretch="Fill"/>
</Button.Background>
</Button>
<Button Name="btnServiceShort" BorderBrush="{x:Null}" Foreground="{x:Null}" Height="20" Width="20" Margin="0,0,0,5" Cursor="Hand">
<Button.Background>
<ImageBrush ImageSource="/maintenance_30px.png" Stretch="Fill"/>
</Button.Background>
</Button>
<Button Name="btnBagsShort" BorderBrush="{x:Null}" Foreground="{x:Null}" Height="20" Width="20" Margin="0,0,0,5" Cursor="Hand">
<Button.Background>
<ImageBrush ImageSource="/waste_30px.png" Stretch="Fill"/>
</Button.Background>
</Button>
<Rectangle Name="rec5" Height="170"/>
<Button Name="btnChatShort" BorderBrush="{x:Null}" Foreground="{x:Null}" Height="20" Width="20" Margin="0,0,0,5" Cursor="Hand">
<Button.Background>
<ImageBrush ImageSource="/chat_30px.png" Stretch="Fill"/>
</Button.Background>
</Button>
<Button Name="btnHelpShort" BorderBrush="{x:Null}" Foreground="{x:Null}" Height="20" Width="20" Margin="0,0,0,5" Cursor="Hand">
<Button.Background>
<ImageBrush ImageSource="/help_30px.png" Stretch="Fill"/>
</Button.Background>
</Button>
<Button Name="btnLogOutShort" BorderBrush="{x:Null}" Foreground="{x:Null}" Height="20" Width="20" Margin="0,0,0,5" Click="BtnLogOut_Click" Cursor="Hand">
<Button.Background>
<ImageBrush ImageSource="/exit_sign_30px.png" Stretch="Fill"/>
</Button.Background>
</Button>
<Rectangle Name="rec6" Height="10"/>
</StackPanel>
<materialDesign:Clock Name="clClock" Width="675" Height="22" FontFamily="Arial" FontWeight="SemiBold" FontSize="10" Foreground="White" Margin="0,578,0,0"/>
<Grid Width="645" Height="550" Margin="0,25,25,25" Name="stackForms">
</Grid>
</DockPanel>
</materialDesign:Card>
</materialDesign:Card>
The place for the grid is where I want the form to be displayed.
The Window cs code is as follows:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using System.Windows.Forms;
using System.Configuration;
using Application = System.Windows.Application;
namespace SolAquaPro
{
/// <summary>
/// Interaction logic for winHomeDash.xaml
/// </summary>
public partial class WinHomeDash : Window
{
public WinHomeDash()
{
InitializeComponent();
}
private void LblDateTime_Loaded(object sender, RoutedEventArgs e)
{
}
private void BtnLogOut_Click(object sender, RoutedEventArgs e)
{
this.Close();
Window main = new MainWindow();
main.Show();
}
public void BtnMenuShort_Click(object sender, RoutedEventArgs e)
{
if ((card2.Visibility == Visibility.Visible) && (btnCollapse.Visibility == Visibility.Visible))
{
card2.Width = 45;
card2.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
btnBags.Visibility = Visibility.Hidden;
btnChat.Visibility = Visibility.Hidden;
btnFuel.Visibility = Visibility.Hidden;
btnHome.Visibility = Visibility.Hidden;
btnMenu.Visibility = Visibility.Hidden;
btnLogOut.Visibility = Visibility.Hidden;
btnService.Visibility = Visibility.Hidden;
btnHelp.Visibility = Visibility.Hidden;
btnTyres.Visibility = Visibility.Hidden;
btnCollapse.Visibility = Visibility.Hidden;
btnExpand.Visibility = Visibility.Visible;
}
else
{
if ((card2.Visibility == Visibility.Visible) && (btnCollapse.Visibility == Visibility.Hidden))
{
card2.Width = 210;
card2.HorizontalAlignment = System.Windows.HorizontalAlignment.Left;
btnBags.Visibility = Visibility.Visible;
btnChat.Visibility = Visibility.Visible;
btnFuel.Visibility = Visibility.Visible;
btnHome.Visibility = Visibility.Visible;
btnMenu.Visibility = Visibility.Visible;
btnLogOut.Visibility = Visibility.Visible;
btnService.Visibility = Visibility.Visible;
btnHelp.Visibility = Visibility.Visible;
btnTyres.Visibility = Visibility.Visible;
btnCollapse.Visibility = Visibility.Visible;
btnExpand.Visibility = Visibility.Hidden;
}
}
}
public void Window_Loaded(object sender, RoutedEventArgs e)
{
lblName.Content = Application.Current.Resources["UserAssign"].ToString();
}
private void BtnFuel_Click(object sender, RoutedEventArgs e)
{
Form frmFuelDash = new FuelDash();
frmFuelDash.Show();
}
protected override void OnMouseLeftButtonDown(MouseButtonEventArgs e)
{
base.OnMouseLeftButtonDown(e);
DragMove();
}
}
}
Thank you in advance
You could try to refer to the following code to see if it matches yours.
If you have any questions, please let me know.
Right-click the reference under the project and select Add Reference....
Check System.Windows.Forms and WindowsFormsIntegration and click OK.
Project structure:
MainWindow.xaml:
<DockPanel >
<Grid x:Name="grid" Background="LightYellow" Width="500" Height="400">
</Grid>
<StackPanel x:Name="sp1" Width="200" Height="100" Background="LightSkyBlue" >
<Button x:Name="btn1" Width="80" Height="30" Background="LightGray" Content="form1" Click="btn1_Click" />
<Button x:Name="btn2" Width="80" Height="30" Background="LightGray" Content="form2" Click="btn2_Click"/>
</StackPanel>
</DockPanel>
MainWindow.xaml.cs:
using System.Windows;
using System.Windows.Forms.Integration;
namespace WpfShowForm
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
}
private void btn1_Click(object sender, RoutedEventArgs e)
{
Form1 f1 = new Form1();
f1.TopLevel = false;
WindowsFormsHost host1 = new WindowsFormsHost();
host1.Child=f1;
grid.Children.Add(host1);
}
private void btn2_Click(object sender, RoutedEventArgs e)
{
Form2 f2 = new Form2();
f2.TopLevel = false;
WindowsFormsHost host2 = new WindowsFormsHost();
host2.Child = f2;
grid.Children.Add(host2);
}
}
}
Add button in Form1:
private void button1_Click(object sender, EventArgs e)
{
Form2 f2 = new Form2();
f2.Show();
}
The Result:
I use on my MainPage a Pivot with 3 PivotItems.
In every PivotItem is a grid. In one of them I want to draw a hydraulic circuit. Therefore I inserted some Columns and Rows to give every element a fixed position in a cell. I need to know the size of the grid because depending on this size the lines (representing pipes of the circuit) are positioned in the middle of a cell and have the half length (or height depending on direction) of the cell.
Here you can see how it should look like in the end. Some of the lines aren´t in their right place when the Raspberry 3 is connected to another Display.
Furthermore the screen is not filled completly with the grid, as can be seen here. Under the circuit is still some white space, but with the same settings this does not happen on the other PivotItems.
When I want to get the Size of a Cell (all cells have the same size! sizing with
*) using:
double columnWidth = circuitGrid.ColumnDefinitions[0].ActualWidth;
I get as result 0.
When i use instead:
double columnWidth = circuitGrid.ColumnDefinitions[0].Width;
I get as result NaN.
The same behaviour I get using:
var circuitGridSize = new Size(circuitGrid.ActualWidth, circuitGrid.ActualHeight);
What I´ve tried:
using the UI element properties Height and ActualHeight
using Properties with and without Size Type
Putting initCircuit function into several Loaded Events
Does someone have a solution for this problem?
Thank you very much!
Here is the MainPage.xaml:
<Page
x:Class="I2cPortExpander.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:I2cPortExpander"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}" Margin="0">
<StackPanel>
<Pivot Margin="0" Height="769" >
<PivotItem x:Name="AutoMode1" Header="Automatikbetrieb" Margin="0">
<FlipView>
<FlipViewItem>
<Grid x:Name="Auto1Grid" Background="LightGray" Visibility="Visible">
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock Text="Anzahl der zu prüfenden Kreisläufe:" Style="{ThemeResource BaseTextBlockStyle}"/>
<RadioButton x:Name="Option1Cycle" Content="1" HorizontalAlignment="Center" Checked="Option1Cycle_Checked"/>
<RadioButton x:Name="Option2Cycle" Content="2" HorizontalAlignment="Center" Checked="Option2Cycle_Checked"/>
<RadioButton x:Name="Option3Cycle" Content="3" HorizontalAlignment="Center" Checked="Option3Cycle_Checked"/>
</StackPanel>
</Grid>
</FlipViewItem>
<FlipViewItem>
<Grid x:Name="Auto2Grid" Background="LightGray" Visibility="Visible">
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock TextWrapping="Wrap" Text="Festlegen der Zeiten der Prüfschritte in Minuten " Margin="0,0,0,20" FontSize="20"/>
<TextBlock x:Name="airTimeText" TextWrapping="Wrap" Text="Druckprüfung mit Luft: 0 Minuten" />
<Slider x:Name="airTimeSlider" HorizontalAlignment="Center" VerticalAlignment="Top" Width="500" Margin="0,0,0,20" TickFrequency="10" Maximum="100" TickPlacement="BottomRight" ValueChanged="airTimeSlider_ValueChanged" />
<TextBlock x:Name="cleanTimeText" TextWrapping="Wrap" Text="Spülgang: 0 Minuten"/>
<Slider x:Name="cleanTimeSlider" HorizontalAlignment="Center" VerticalAlignment="Top" Width="500" Margin="0,0,0,20" TickFrequency="10" Maximum="100" TickPlacement="BottomRight" ValueChanged="cleanTimeSlider_ValueChanged"/>
<TextBlock x:Name="oilTimeText" TextWrapping="Wrap" Text="Drückprüfung mit Öl: 0 Minuten"/>
<Slider x:Name="oilTimeSlider" HorizontalAlignment="Center" VerticalAlignment="Top" Width="500" Margin="0,0,0,20" TickFrequency="10" Maximum="100" TickPlacement="BottomRight" ValueChanged="oilTimeSlider_ValueChanged"/>
<TextBlock x:Name="flowRateTimeText" TextWrapping="Wrap" Text="Durchflussmessung: 0 Minuten"/>
<Slider x:Name="flowRateTimeSlider" HorizontalAlignment="Center" VerticalAlignment="Top" Width="500" Margin="0,0,0,20" TickFrequency="10" Maximum="100" TickPlacement="BottomRight" ValueChanged="flowRateTimeSlider_ValueChanged"/>
<TextBlock x:Name="blowTimeText" TextWrapping="Wrap" Text="Ausblasen: 0 Minuten"/>
<Slider x:Name="blowTimeSlider" HorizontalAlignment="Center" VerticalAlignment="Top" Width="500" Margin="0,0,0,20" TickFrequency="10" Maximum="100" TickPlacement="BottomRight" ValueChanged="blowTimeSlider_ValueChanged"/>
</StackPanel>
</Grid>
</FlipViewItem>
<FlipViewItem>
<Grid x:Name="Auto3Grid" Background="LightGray" Visibility="Visible">
<StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock TextWrapping="Wrap" Text="Festlegen der Druckparameter in Bar " Margin="0,0,0,20" FontSize="20"/>
<TextBlock x:Name="desiredPressure" TextWrapping="Wrap" Text="Druckprüfung mit: 0 Bar" />
<Slider x:Name="desiredPressureSlider" HorizontalAlignment="Center" VerticalAlignment="Top" Width="500" Margin="0,0,0,20" TickFrequency="2" Maximum="20" TickPlacement="BottomRight" ValueChanged="desiredPressureSlider_ValueChanged" />
<TextBlock x:Name="breakPressure" TextWrapping="Wrap" Text="Maximaler Druckverlust während Prüfung: 0 Bar"/>
<Slider x:Name="breakPressureSlider" HorizontalAlignment="Center" VerticalAlignment="Top" Width="500" Margin="0,0,0,20" TickFrequency="1" Maximum="10" TickPlacement="BottomRight" ValueChanged="breakPressureSlider_ValueChanged"/>
<Grid>
<Button x:Name="Automatik3_Start" Content="Start" HorizontalAlignment="Right" VerticalAlignment="Stretch" Margin="10" Width="75" Click="Automatik3_Start_Click"/>
</Grid>
</StackPanel>
</Grid>
</FlipViewItem>
</FlipView>
</PivotItem>
<PivotItem x:Name="HandModus" Header="Handbetrieb" Margin="0">
<Grid x:Name="circuitGrid" Background="LightGray" Visibility="Visible" Margin="0" >
<Grid.RowDefinitions>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
<RowDefinition Height="*"/>
</Grid.RowDefinitions>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
<ColumnDefinition Width="*"/>
</Grid.ColumnDefinitions>
<Ellipse x:Name="pneuConOuterCirc" Grid.Column="0" Grid.Row="1" Stroke="Black" HorizontalAlignment="Center" VerticalAlignment="Center"/>
<Ellipse x:Name="pneuConInnerCirc" Grid.Column="0" Grid.Row="1" Fill="Black" HorizontalAlignment="Center" VerticalAlignment="Center"/>
<Button x:Name="HandModeAir" Content="Luft" HorizontalAlignment="Stretch" VerticalAlignment="Center" Grid.Column="1" Grid.Row="1" Background="Gray" Click="HandModeAir_Click"/>
<Button x:Name="HandModeCycle1" Content="Kreislauf 1" HorizontalAlignment="Stretch" VerticalAlignment="Center" Grid.Column="3" Grid.Row="0" Background="Gray" Click="HandModeCycle1_Click"/>
<Button x:Name="HandModeCycle2" Content="Kreislauf 2" HorizontalAlignment="Stretch" VerticalAlignment="Center" Grid.Column="3" Grid.Row="1" Background="Gray" Click="HandModeCycle2_Click"/>
<Button x:Name="HandModeCycle3" Content="Kreislauf 3" HorizontalAlignment="Stretch" VerticalAlignment="Center" Grid.Column="3" Grid.Row="2" Background="Gray" Click="HandModeCycle3_Click"/>
<Button x:Name="HandModeWaySelector" Content="Pumpe RL" HorizontalAlignment="Stretch" VerticalAlignment="Top" Canvas.Left="0" Grid.Column="6" Grid.Row="5" Background="Gray" Click="HandModeWaySelector_Click"/>
<Button x:Name="HandModePump" Content="Pumpe Aus" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Grid.Column="2" Grid.Row="3" Background="Gray" Click="HandModePump_Click" />
<Button x:Name="HandModeMeasureSelector" Content="zu" HorizontalAlignment="Stretch" VerticalAlignment="Top" Grid.Column="4" Grid.Row="7" Background="Gray" Click="HandModeMeasureSelector_Click" />
<TextBlock Text="Werkzeug" Grid.Column="5" Grid.Row="1" VerticalAlignment="Center" HorizontalAlignment="Center" RenderTransformOrigin="0.5,0.5" >
<TextBlock.RenderTransform>
<CompositeTransform Rotation="90"/>
</TextBlock.RenderTransform>
</TextBlock>
<Rectangle Stroke="Black" StrokeThickness="4" Grid.Column="5" Grid.Row="0" Grid.RowSpan="3"/>
<Rectangle x:Name="Line1" Grid.Column="0" Grid.Row="1" Height="10" Fill="Green" Width="48" HorizontalAlignment="Right"/>
<Rectangle x:Name="Line2" Grid.Column="2" Grid.Row="1" Height="10" Fill="Red" HorizontalAlignment="Stretch" />
<Rectangle x:Name="Line4" Grid.Column="2" Grid.Row="2" Width="65" Fill="Red" Height="10" HorizontalAlignment="Right"/>
<Rectangle x:Name="Line3" Grid.Column="2" Grid.Row="0" Fill="Red" Height="10" Width="65" HorizontalAlignment="Right"/>
<Rectangle x:Name="Line5" Grid.Column="2" Grid.Row="0" Fill="Red" Width="10" Height="65" VerticalAlignment="Bottom"/>
<Rectangle x:Name="Line6" Grid.Column="2" Grid.Row="1" Width="10" Fill="Red" VerticalAlignment="Stretch" />
<Rectangle x:Name="Line7" Grid.Column="4" Grid.Row="0" Height="10" Fill="Red" HorizontalAlignment="Stretch"/>
<Rectangle x:Name="Line8" Grid.Column="4" Grid.Row="1" Height="10" Fill="Red" HorizontalAlignment="Stretch"/>
<Rectangle x:Name="Line9" Grid.Column="4" Grid.Row="2" Height="10" Fill="Red" HorizontalAlignment="Stretch"/>
<Rectangle x:Name="Line10" Grid.Column="6" Grid.Row="0" Fill="Red" Height="10" Width="65" HorizontalAlignment="Left"/>
<Rectangle x:Name="Line11" Grid.Column="6" Grid.Row="1" Fill="Red" Height="10" Width="65" HorizontalAlignment="Left"/>
<Rectangle x:Name="Line12" Grid.Column="6" Grid.Row="2" Fill="Red" Height="10" Width="65" HorizontalAlignment="Left"/>
<Rectangle x:Name="Line13" Grid.Column="6" Grid.Row="0" Fill="Red" Width="10" Height="65" VerticalAlignment="Bottom"/>
<Rectangle x:Name="Line14" Grid.Column="6" Grid.Row="1" Grid.RowSpan="4" Fill="Red" Width="10"/>
<Rectangle x:Name="Line15" Fill="RED" Grid.Column="5" Grid.Row="5" Grid.ColumnSpan="1" Height="10" HorizontalAlignment="Stretch" VerticalAlignment="Top" />
<Rectangle x:Name="Line16" Fill="RED" Grid.Column="3" Grid.Row="5" Height="10" HorizontalAlignment="Stretch" VerticalAlignment="Top"/>
<Rectangle x:Name="Line17" Grid.Column="2" Grid.Row="5" Fill="Red" Height="10" Width="65" VerticalAlignment="Top" HorizontalAlignment="Right" Canvas.ZIndex="1"/>
<Rectangle x:Name="Line18" Fill="Green" Grid.Column="6" Grid.Row="5" Height="10" Width="65" HorizontalAlignment="Left" Canvas.ZIndex="1"/>
<Rectangle x:Name="Line19" Fill="Green" Grid.Column="3" Grid.Row="5" Grid.ColumnSpan="3" Height="10" HorizontalAlignment="Stretch" Canvas.ZIndex="1"/>
<Rectangle x:Name="Line20" Grid.Column="2" Grid.Row="5" Fill="Green" Height="10" Width="65" HorizontalAlignment="Right" Canvas.ZIndex="1"/>
<Rectangle x:Name="Line21" Grid.Column="2" Grid.Row="5" Fill="Green" Width="10" VerticalAlignment="Stretch" Canvas.ZIndex="1" HorizontalAlignment="Left" Margin="59,0,0,0"/>
<Rectangle x:Name="Line22" Grid.Column="2" Grid.Row="4" Fill="Green" Width="10" Canvas.ZIndex="1"/>
<Rectangle x:Name="Line23" Grid.Column="2" Grid.Row="2" Fill="Red" Width="10" Canvas.ZIndex="1"/>
<Rectangle x:Name="Line24" Grid.Column="6" Grid.Row="5" Fill="Green" Width="10" Height="50" Canvas.ZIndex="1" HorizontalAlignment="Center"/>
<Image Source="images/durchfluss.png" Grid.Column="3" Grid.Row="4" Margin="25,25,25,-10"/>
<Image Source="images/druckmesser.png" Grid.Column="5" Grid.Row="4" Margin="25,25,25,-10"/>
</Grid>
</PivotItem>
<PivotItem x:Name="Properties" Header="Einstellungen" HorizontalAlignment="Left" Margin="0">
<Grid>
</Grid>
</PivotItem>
</Pivot>
</StackPanel>
</Grid>
Here is the MainPage code:
public MainPage()
{
this.InitializeComponent();
InitDisplay();
//this funtion sets up the size of the elements
initCircuit();
// Register for the unloaded event so we can clean up upon exit
Unloaded += MainPage_Unloaded;
I2C.InitializeSystem();
}
Here is the initCircuit function:
private void initCircuit()
{
var displayInformation = DisplayInformation.GetForCurrentView();
var screenSize = new Size(displayInformation.ScreenWidthInRawPixels,
displayInformation.ScreenHeightInRawPixels);
var circuitGridSize = new Size(circuitGrid.ActualWidth,
circuitGrid.ActualHeight);
double screenWidth = screenSize.Width;
double screenHeight = screenSize.Height;
double rowHeight = circuitGridSize.Height / circuitGrid.RowDefinitions.Count;
double gridWidth = circuitGrid.Width;
//Initialisierung des Schaltplanes
//Initialisierung der Verbindungen
//Pneumatikanschluss
pneuConInnerCirc.Height = rowHeight / 2.5;
pneuConOuterCirc.Height = rowHeight / 2;
//Werkzeuganschluss
PathGeometry toolSupplyPathVL = new PathGeometry();
PathGeometry toolSupplyPathRL = new PathGeometry();
//Werkzeugsymbol
//Pumpenanschluss
PathGeometry pumpSupplyPath = new PathGeometry();
//Messzweig
PathGeometry measurePath1 = new PathGeometry();
PathGeometry measurePath2 = new PathGeometry();
//Initialisierung der Aktoren des Schaltplans
//Initialisierung der Messinstrumente
TextBlock actualPressure = new TextBlock();
TextBlock actualFlowrate = new TextBlock();
//-----------------------------------------------//
//Luftanschluss
Line1.Width = ((screenWidth / circuitGrid.ColumnDefinitions.Count) - pneuConOuterCirc.Width) / 2;
Line5.Height = (screenHeight / circuitGrid.RowDefinitions.Count + Line3.Height) / 2;
Line3.Width = (screenWidth / circuitGrid.ColumnDefinitions.Count) / 2;
Line4.Width = (screenWidth / circuitGrid.ColumnDefinitions.Count) / 2;
Line10.Width = (screenWidth / circuitGrid.ColumnDefinitions.Count) / 2;
Line11.Width = (screenWidth / circuitGrid.ColumnDefinitions.Count) / 2;
Line12.Width = (screenWidth / circuitGrid.ColumnDefinitions.Count) / 2;
Line18.Width = (screenWidth / circuitGrid.ColumnDefinitions.Count + Line24.Width) / 2;
Line17.Width = (screenWidth / circuitGrid.ColumnDefinitions.Count) / 2;
Line20.Width = (screenWidth / circuitGrid.ColumnDefinitions.Count) / 2;
Line13.Height = (screenHeight / circuitGrid.RowDefinitions.Count + Line3.Height) / 2;
HandModeWaySelector.Width = (screenWidth / circuitGrid.ColumnDefinitions.Count);
HandModeWaySelector.Height = (screenHeight / circuitGrid.RowDefinitions.Count) / 3;
// Line24.Height= (screenSize.Height / circuitGrid.RowDefinitions.Count)/2 -HandModeWaySelector.Height;
// Line24.VerticalAlignment = VerticalAlignment.Stretch;
Line24.Margin = new Thickness((screenWidth / circuitGrid.ColumnDefinitions.Count - Line24.Width) / 2, HandModeWaySelector.Height / 2, (screenWidth / circuitGrid.ColumnDefinitions.Count - Line24.Width) / 2, (screenHeight / circuitGrid.RowDefinitions.Count) / 2);
Line21.Margin = new Thickness((screenWidth / circuitGrid.ColumnDefinitions.Count - Line24.Width) / 2, 0, (screenWidth / circuitGrid.ColumnDefinitions.Count - Line24.Width) / 2, (screenHeight / circuitGrid.RowDefinitions.Count) / 2 - Line20.Height / 2);
Line15.Margin = new Thickness(0, (HandModeWaySelector.Height / 2 - Line15.Height) / 2, 0, screenHeight / circuitGrid.RowDefinitions.Count - (HandModeWaySelector.Height - Line15.Height / 2));
Line16.Margin = Line15.Margin;
Line17.Margin = new Thickness((screenWidth / circuitGrid.ColumnDefinitions.Count) / 2, (HandModeWaySelector.Height / 2 - Line15.Height) / 2, 0, screenHeight / circuitGrid.RowDefinitions.Count - (HandModeWaySelector.Height - Line15.Height / 2));
}
You should not rely on any measure until the "measuring process" is performed (and stable). Try move the initCircuit call inside a MainPage Loaded handler. You should gain some result.
EDIT: A better approach:
public MainPage()
{
this.InitializeComponent();
this.circuitGrid.SizeChanged += circuitGrid_SizeChanged;
}
private void circuitGrid_SizeChanged(object sender, SizeChangedEventArgs e)
{
//check for valid size
//if (valid) {
// initCircuit()
//}
}
private void initCircuit()
{
//
}
The idea is to "listen" every single grid size change, then evaluate whether to draw or not. The validation is straight to check for NaN or something numeric. I recommend to perform a quick test as validation before doing the concrete initCircuit. That's because you might see a tight sequence of SizeChanged calls, during the initial rendering process.
Not a bullet-proof solution, but at this point you should see the things begin to work.
From the code you provided,the positions of lines are calculated from screenSize which is the size of current app's view.The result of GetForCurrentView is the physical display resolution(please note that, it is not the display resolution).I think the positions should be calculated from circuitGrid.Please refer to the following code:
private void initCircuit()
{
...
double screenWidth = circuitGridSize.Width;
double screenHeight = circuitGridSize.Height;
...
}
In addition, the height of the Pivot is fixed as 769, it will affect the adaptability of the positions. It is better if it configured to fill the StackPanel vertically.
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;
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();
}
}
So I have my AML keypad as such :
<Grid.ColumnDefinitions>
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
<ColumnDefinition Width="Auto" />
</Grid.ColumnDefinitions>
<TextBox Name="btnTotal" Width="280" Height="60" Grid.ColumnSpan="3" Grid.Row="0" Margin="10,10,10,10" Background="#302F37" Foreground="AntiqueWhite" FontSize="35"></TextBox>
<Button x:Name="btnZzero" Content="0" Width="80" Height="60" Grid.Column="0" Grid.Row="4" Margin="5,5,5,5" Background="#302F37" Foreground="White" Focusable="False" Click="btnZzero_Click"></Button>
<Button x:Name="btnOk" Content="OK" Width="80" Height="60" Grid.Column="1" Grid.Row="4" Margin="5,5,5,5" Click="btnOk_Click" Background="#FF8FC377" Focusable="False"></Button>
<Button x:Name="btnCancel" Content="Cancel" Width="80" Height="60" Grid.Column="2" Grid.Row="4" Margin="5,5,5,5" Click="cancel_Click" BorderBrush="Black" Background="#FFD64D4D" Focusable="False"></Button>
<Button x:Name="btnOne" Content="1" Width="80" Height="60" Grid.Column="0" Grid.Row="3" Margin="14,6,0,6" Focusable="False" Background="#302F37" Foreground="White" HorizontalAlignment="Left" Click="btnOne_Click"></Button>
<Button x:Name="btnTwo" Content="2" Width="80" Height="60" Grid.Column="1" Grid.Row="3" Margin="5,5,5,5" Focusable="False" Background="#302F37" Foreground="White" Click="btnTwo_Click"/>
<Button x:Name="btnThree" Content="3" Width="80" Height="60" Grid.Column="2" Grid.Row="3" Margin="5,5,5,5" Focusable="False" Background="#302F37" Foreground="White" Click="btnThree_Click"/>
<Button x:Name="btnFour" Content="4" Width="80" Height="60" Grid.Column="0" Grid.Row="2" Margin="5,5,5,5" Focusable="False" Background="#302F37" Foreground="White" Click="btnFour_Click"></Button>
<Button x:Name="btnFive" Content="5" Width="80" Height="60" Grid.Column="1" Grid.Row="2" Margin="5,5,5,5" Focusable="False" Background="#302F37" Foreground="White" Click="btnFive_Click"></Button>
<Button x:Name="btnSix" Content="6" Width="80" Height="60" Grid.Column="2" Grid.Row="2" Margin="5,5,5,5" Focusable="False" Background="#302F37" Foreground="White" Click="btnSix_Click"></Button>
<Button x:Name="btnSeven" Content="7" Width="80" Height="60" Grid.Column="0" Grid.Row="1" Margin="12,5,9,6" Focusable="False" Background="#302F37" Foreground="White" Click="btnSeven_Click"></Button>
<Button x:Name="btnEight" Content="8" Width="80" Height="60" Grid.Column="1" Grid.Row="1" Margin="5,5,5,5" Focusable="False" Background="#302F37" Foreground="White" Click="btnEight_Click"></Button>
<Button x:Name="btnNine" Content="9" Width="80" Height="60" Grid.Column="2" Grid.Row="1" Margin="5,5,5,5" Focusable="False" Background="#302F37" Foreground="White" Click="btnNine_Click"></Button>
Now I want to write a small helper method to run when each button is clicked but I cannot work out how to use the Content from the XAML.
for example this works for button 1 :
private void btnOne_Click(object sender, RoutedEventArgs e)
{
addButtonNumberToResult();
}
And the helper method uses btnOne.Content but how do I get it to use the Content from any button being pressed? So I can just add the helper methosto each button?
private void addButtonNumberToResult() //helper method
{
if (btnClicked == true)
{
btnTotal.Text = "";
btnClicked = false;
}
QuantityResult = QuantityResult += btnOne.Content;
btnTotal.Text = QuantityResult;
}
You can use the sender variable to determine the button clicked:
private void btn_Click(object sender, RoutedEventArgs e)
{
addButtonNumberToResult((Button)sender);
}
add btn_Click to the Click event of each button (and replace the ones you have already)
private void addButtonNumberToResult(Button btn) //helper method
{
if (btnClicked == true)
{
btnTotal.Text = "";
btnClicked = false;
}
QuantityResult = QuantityResult += btn.Content;
btnTotal.Text = QuantityResult;
}