I want to make border and textblock disappear when i click the button and the border and textblock appear when i click the button again.
This is my xaml:
<Border x:Name="descbox" Background="#A6CFC9A8" Height="80" VerticalAlignment="Bottom" Visibility="Visible" Margin="0,-100,0,0">
<ScrollViewer VerticalScrollMode="Auto" Height="auto" Margin="0,0,0.333,0" HorizontalScrollBarVisibility="Visible">
<StackPanel Width="548">
<TextBlock x:Name="desc" Text="{Binding Description}" FontFamily="verdana" FontSize="19" Foreground="#CC000000" TextWrapping="Wrap" Padding="0,10" TextAlignment="Justify" Margin="0,0,10.333,0"/>
</StackPanel>
</ScrollViewer>
</Border>
<Button Content="Button"/>
How to make it in windows phone 8.1?
XAML :
<Button Content="Button" Click="Button_Click"/>
Code :
private void Button_Click(object sender, RoutedEventArgs e)
{
if (descbox.Visibility == Visibility.Visible)
descbox.Visibility = Visibility.Collapsed;
else
descbox.Visibility = Visibility.Visible;
}
Related
Write a text in the inputTitle TextBox and press the Add button to add item to the TaskList ListView.
public MainWindow()
{
InitializeComponent();
DataContext = new AddItem();
newItems = new ObservableCollection<AddItem> { };
taskList.ItemsSource = newItems;
}
private void addButton_Click(object sender, RoutedEventArgs e)
{
var newItem = new AddItem()
{
Title = inputTitle.Text,
};
newItems.Add(newItem);
taskList.SelectedItem = newItem;
}
private void deleteButton_Click(object sender, RoutedEventArgs e)
{
}
It is to add item to TaskList by pressing the Add button, and I want to delete it by pressing Del button.
<Canvas Margin="0,0,0,10">
<Canvas Height="81" Canvas.Left="10" Canvas.Top="17" Width="380">
<TextBlock x:Name="textBlock" Text="TaskTitle" TextWrapping="Wrap" Height="24" Width="380" FontSize="20" IsEnabled="False"/>
<TextBox x:Name="inputTitle" Text="{Binding Title, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}" TextWrapping="Wrap" Width="320" FontSize="24" Canvas.Top="27" Height="44" TabIndex="1" Canvas.Left="4" Margin="2,2,2,2"/>
<Button x:Name="addButton" Content="Add" Canvas.Left="333" Canvas.Top="32" Height="34" Width="34" Click="addButton_Click" IsEnabled="{Binding CanAdd, Mode=OneWay, UpdateSourceTrigger=PropertyChanged}"/>
</Canvas>
<ListView x:Name="taskList" Height="500" Width="400" Canvas.Top="116">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<CheckBox >
<CheckBox.LayoutTransform>
<ScaleTransform ScaleX="2.5" ScaleY="2.5"/>
</CheckBox.LayoutTransform>
</CheckBox>
<TextBlock Text="{Binding Title}" FontSize="30" Width="290"/>
<Button x:Name="deleteButton" Content="Del" Height="34" Width="34" Click="deleteButton_Click"/>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
</Canvas>
You can bind the Tag property of Button to the current item.
<ListView x:Name="taskList" Height="500" Width="400" Canvas.Top="116" ItemsSource="{Binding newItems}">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<CheckBox >
<CheckBox.LayoutTransform>
<ScaleTransform ScaleX="2.5" ScaleY="2.5"/>
</CheckBox.LayoutTransform>
</CheckBox>
<TextBlock Text="{Binding Title}" FontSize="30" Width="290"/>
<Button x:Name="deleteButton" Content="Del" Height="34" Width="34" Click="deleteButton_Click" Tag="{Binding}"/>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
As you bind the Tag property to your current item, you can use that to remove it from the collection.
private void ButtonBase_OnClickDel(object sender, RoutedEventArgs e)
{
var button = (Button)sender;
var item = (AddItem)button.Tag;
newItems.Remove(item);
}
i want to send Data from one Textbox on window One to a label on window Two.
starting with window two:
<StackPanel>
<StackPanel x:Name="ButtonStackPanel" Height="Auto" Width="Auto">
<StackPanel Orientation="Horizontal">
<StackPanel Orientation="Vertical">
<Button Style="{DynamicResource ButtonStyle}" Content="To The Dark Side" Click="OnClickToDarkSide"/>
<Button Style="{DynamicResource ButtonStyle}" Content="To The Gray" Click="OnClickToGraySide"/>
<Button Style="{DynamicResource ButtonStyle}" Content="To The Light Side" Click="OnClickToLightSide"/>
</StackPanel>
<Border HorizontalAlignment="Center" VerticalAlignment="Stretch" Background="Red" Height="Auto" Width="2"/>
<Label Style="{DynamicResource LabelStyle}" x:Name="theTextBlock" Content="{Binding Source=CodeText}"/>
<Border HorizontalAlignment="Center" VerticalAlignment="Stretch" Background="Red" Height="Auto" Width="2"/>
<ToggleButton Style="{DynamicResource ToggleButtonStyle}" Content="Open Style Window" Name="StyleWindowButton" Click="OnClickOpenStyleWindow"/>
<ToggleButton Style="{DynamicResource ToggleButtonStyle}" Content="Open Text Window" Name="TextWindowButton" Click="OnClickOpenTextWindow"/>
</StackPanel>
<Border Height="2" Width="Auto" Background="Red" HorizontalAlignment="Stretch" VerticalAlignment="Center"/>
</StackPanel>
<Border Height="2" Width="Auto" Background="Red" HorizontalAlignment="Stretch" VerticalAlignment="Center"/>
</StackPanel>
Codebehind of Window Two:
public MainWindow()
{
(App.Current as App).CodeText = _jediCode;
InitializeComponent();
}
private void OnClickToDarkSide(object sender, RoutedEventArgs e)
{
(App.Current as App).ChangeSkin(Skin.Dark);
(App.Current as App).CodeText = _sithCode;
theTextBlock.Content = (App.Current as App).CodeText;
}
private void OnClickToLightSide(object sender, RoutedEventArgs e)
{
(App.Current as App).ChangeSkin(Skin.Light);
(App.Current as App).CodeText = _jediCode;
theTextBlock.Content = (App.Current as App).CodeText;
}
private void OnClickToGraySide(object sender, RoutedEventArgs e)
{
(App.Current as App).ChangeSkin(Skin.Gray);
(App.Current as App).CodeText = _grayCode;
theTextBlock.Content = (App.Current as App).CodeText;
}
private void OnClickOpenStyleWindow(object sender, RoutedEventArgs e)
{
if (StyleWindowButton.IsChecked == true)
{
styleWindow = new StyleWindow();
styleWindow.Show();
}
else
{
styleWindow.Close();
styleWindow = null;
}
}
private void OnClickOpenTextWindow(object sender, RoutedEventArgs e)
{
if (TextWindowButton.IsChecked == true)
{
textWindow = new InputWindow();
textWindow.Show();
}
else
{
textWindow.Close();
textWindow = null;
}
}
}
window one:
<Grid>
<TextBox HorizontalAlignment="Left" VerticalAlignment="Top" Height="200" Width="200" TextWrapping="Wrap"
AcceptsReturn="True" AcceptsTab="True" Text="{Binding Path=CodeText, Source={x:Static Application.Current}, UpdateSourceTrigger=PropertyChanged, Mode=TwoWay}" Margin="10,10,0,0">
<!-- TODO: trigger change from this textbox to the textblock in mainwindow -->
</TextBox>
</Grid>
code behind of one is empty.
app.xaml.cs:
public string CodeText
{
get => _codeText;
set { _codeText = value; OnPropertyChanged(nameof(CodeText)); }
}
Ok, the current behavior is clicking on one of the buttons (Dark Side, Gray, Light Side) leads to changes in the CodeText Property, which leads to a change of the content of the label of Window Two and the text of TextBox of Window One. Changing the text of the TextBox, changes also the CodeText Property, but does not lead to a change in the label and thats confusing, why does it work the one way, but not the other.
hope you have a hint for me. :) Maybe i missed a trigger or a kind of refresh for the label
bindings in window One and Two are set differently. (window Two does it wrong, Content="{Binding Source=CodeText}" is not valid binding)
in fact, window Two removes the binding by assigning CodeText directly as local value:
theTextBlock.Content = (App.Current as App).CodeText;
you should remove that line, and use the same binding as in window One:
<Label Style="{DynamicResource LabelStyle}" x:Name="theTextBlock"
Content="{Binding Path=CodeText, Source={x:Static Application.Current}}"/>
I want to open an Edit-page i've created when i click on the MenuFlyoutItem. Heres the code for my ListView:
<ListView Name="ModelListXAML" Grid.Row="1" Margin="0,12,0,0" CanDragItems="True" SelectionChanged="ModelListXAML_SelectionChanged" ItemClick="ModelListXAML_ItemClick">
<ListView.ItemTemplate>
<DataTemplate>
<Grid Margin="0,0,0,5" Holding="ModellItem_Holding">
<FlyoutBase.AttachedFlyout>
<MenuFlyout>
<MenuFlyoutItem x:Name="ModellMenuEdit" Click="ModellMenuEdit_Click" Text="Bearbeiten"/>
<MenuFlyoutItem x:Name="ModellMenuDelete" Click="ModellMenuDelete_Click" Text="Löschen"/>
</MenuFlyout>
</FlyoutBase.AttachedFlyout>
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition Height="auto"/>
</Grid.RowDefinitions>
<StackPanel Margin="10, 0,0,0">
<TextBlock Text="{Binding name}" FontFamily="Segoe WP Semibold" FontSize="30" HorizontalAlignment="Left" Grid.Row="0"/>
<TextBlock Text="{Binding captions}" FontFamily="Segoe WP Semibold" FontSize="20" HorizontalAlignment="Left" Grid.Row="1" Foreground="Gray"/>
</StackPanel>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
My Problem is, that the app crashes, when the ModellMenuEdit_Click event get's fired. Visual Studio gives me this Error:
#if DEBUG && !DISABLE_XAML_GENERATED_BREAK_ON_UNHANDLED_EXCEPTION
UnhandledException += (sender, e) =>
{
if (global::System.Diagnostics.Debugger.IsAttached) global::System.Diagnostics.Debugger.Break();
};
#endif
And here's the Code for the ModelMenuEdit_Click event:
private void ModellMenuEdit_Click(object sender, RoutedEventArgs e)
{
Modell datacontext = (e.OriginalSource as FrameworkElement).DataContext as Modell;
Frame.Navigate(typeof(ModellEdit));
}
Any idea how to solve this? Thank's for any response in advance :)
The problem is with the way you're trying to retrieve the DataContext. Try this:
private void ModellMenuEdit_Click(object sender, RoutedEventArgs e)
{
var menuFlyoutItem = sender as MenuFlyoutItem;
Modell datacontext;
if (menuFlyoutItem != null)
{
datacontext = menuFlyoutItem.DataContext as Modell;
}
Frame.Navigate(typeof(ModellEdit), /*in case you want to pass datacontext*/ datacontext);
}
I've solved it! The actual problem was in the OnNavigatedTo() Method for the ModellEdit page :)
I have created a text box which when focused brings up a popup box with other text box's as options.. and when pressed closes the popup box.. but I'd like that to then take the value from whichever text box I have selected and add into the original text box. Is this possible? I'm new to wpf so forgive me!
Here is my code so far.
<Grid>
<StackPanel Margin="0,51,0,-51">
<TextBox x:Name="text" GotKeyboardFocus="text_GotKeyboardFocus" Margin="158,0,169,0" Height="24" Text="Select Your Time..." />
<Popup x:Name="popup" Width="282" Height="300" PlacementTarget="{Binding ElementName=text}">
<Grid>
<StackPanel>
<TextBox x:Name="text2" Background="White" Margin="10" GotKeyboardFocus="text_GotKeyboardFocus2" Cursor="Arrow" Height="24" Text="1 second" />
<TextBox x:Name="text3" Background="White" Margin="10" GotKeyboardFocus="text_GotKeyboardFocus2" Cursor="Arrow" Height="24" Text="2 second" />
<TextBox x:Name="text4" Background="White" Margin="10" GotKeyboardFocus="text_GotKeyboardFocus2" Cursor="Arrow" Height="24" Text="3 second" />
<TextBox x:Name="text5" Background="White" Margin="10" GotKeyboardFocus="text_GotKeyboardFocus2" Cursor="Arrow" Height="24" Text="4 second" />
<TextBox x:Name="text6" Background="White" Margin="10" GotKeyboardFocus="text_GotKeyboardFocus2" Cursor="Arrow" Height="24" Text="5 second" />
</StackPanel>
</Grid>
</Popup>
</StackPanel>
</Grid>
private void text_GotKeyboardFocus(object sender, KeyboardFocusChangedEventArgs e)
{
popup.IsOpen = true;
}
private void text_GotKeyboardFocus2(object sender, RoutedEventArgs e)
{
popup.IsOpen = false;
}
Get value from one textbox to another in xaml:
<TextBox Name="txtBox1"/>
<TextBox Name="txtBox2" Text="{Binding ElementName=txtBox1, Path=Text,UpdateSourceTrigger=PropertyChanged}" />
I hope I got your point.
Just add text.Text = (sender as TextBox).Text; to your second event handler as follows :
private void text_GotKeyboardFocus2(object sender, RoutedEventArgs e)
{
popup.IsOpen = false;
text.Text = (sender as TextBox).Text;
}
Good luck.
Get value from one textbox to another XAML
<TextBox Name="txtBox1"/>
<TextBox Name="txtBox2" Text="{Binding ElementName=txtBox1, Path=Text,UpdateSourceTrigger=PropertyChanged}" />
I have a gridView.
ıt has an Itemptemplate (textblock, image) and itemsource. textBlock and Image are binded to itemsource.
I want to add a button to ItempTemplate but I couldn't able to detect the eventHandler.
In my .cs file I dont see textblock, image or button.
how can I set the event,
here is the code of item template
<DataTemplate x:Key="IDViewStyle">
<Grid Width="350" Height="450" >
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition Height="40"/>
</Grid.RowDefinitions>
<Grid>
<Border Background="#B2060606" />
<Button HorizontalAlignment="Right" BorderThickness="0" x:Name="eraseButton" VerticalAlignment="Top">
<Image Source="/Assets/Images/erease.png" Width="90" Margin="0,-7,-15,15"/>
</Button>
<StackPanel Margin="0" Orientation="Vertical" HorizontalAlignment="Center" VerticalAlignment="Center">
<TextBlock HorizontalAlignment="Center" TextWrapping="Wrap" Text="+" VerticalAlignment="Center" Style="{StaticResource PageHeaderTextStyle}" FontSize="160" Margin="0"/>
<TextBlock TextWrapping="Wrap" Text="Ekle" TextAlignment="Center" Style="{StaticResource HeaderTextStyle}"/>
</StackPanel>
<Image Stretch="Fill" Source="{Binding Image}"/>
</Grid>
<TextBlock TextWrapping="Wrap" Text="{Binding Type}" VerticalAlignment="Top" Grid.Row="1" Style="{StaticResource SubheaderTextStyle}" TextAlignment="Center"/>
</Grid>
</DataTemplate>
and my .cs file
Data.IdentityTypeCollection collection;
gView.SelectionChanged += lvIdTypes_SelectionChanged;
collection = new Data.IdentityTypeCollection();
gView.ItemsSource = collection;
gView.ScrollIntoView(collection);
and my mainpage.xaml
<GridView x:Name="gView" Grid.Row="1" Grid.RowSpan="2" Margin="117,0,0,100" ItemTemplate="{StaticResource IDViewStyle}"/>
how can I use button event in the item template
On GridView you can assign a property ItemClick="YourClickEvent" like:
<GridView
x:Name="itemGridView"
IsItemClickEnabled="True"
ItemClick="ItemView_ItemClick"></GridView>
and in your .cs file the event handler:
void YourClickEvent(object sender, ItemClickEventArgs e)
{
//your codes here
}
Make sure GridView IsItemClickEnabled is set to True All set!
If I understand your question then this is what I did after using the debugger to look around. This is a UWP application. The Button is in a Grid in a DataTemplate in a "MedView" GridView. The following sets the ItemsSource:
List<ViewItemClass> lvil = new List<ViewItemClass>();
// create lvil
MedView.ItemsSource = lvil;
Then I added a Click event handler for the Button and the following is the code for that:
Button b = sender as Button;
if (b == null)
return;
Grid g = b.Parent as Grid;
if (g == null)
return;
ViewItemClass lvi = g.DataContext as ViewItemClass;
if (lvi == null)
return;
// use the item