WPF Issue with same ALT hotkey - c#

I have a window with 3 textboxes and labels with following properties:
<Label x:Name="label" Content="_Label" Target="{Binding ElementName=textBox}"/>
<Label x:Name="label1" Content="Label"/>
<Label x:Name="label2" Content="_Label" Target="{Binding ElementName=textBox2}"/>
See this image
You can see that "label" and "label2" have the same ALT + L key but different Target property. When I focus textBox middle and I press ALT + L I need that textBox2 is focues (like in MFC). I can't use code behide because I was made about 200 windows.
Thanks a lot!

I think if you really need with out code behind or ViewModel you can do it by adding the same short cut to Label1 like below,
<Label x:Name="label" Grid.Row="0" Content="_Label" Target="{Binding ElementName=textBox}"/>
<Label x:Name="label1" Grid.Row="1" Content="_Label" Target="{Binding ElementName=textBox1}"/>
<Label x:Name="label2" Grid.Row="2" Content="_Label" Target="{Binding ElementName=textBox2}"/>
<TextBox x:Name="textBox" Grid.Column="1" Grid.Row="0"/>
<TextBox x:Name="textBox1" Grid.Column="1" Grid.Row="1"/>
<TextBox x:Name="textBox2" Grid.Column="1" Grid.Row="2"/>
If you can make a ViewModel then InputBinding with KeyBinding can make it work.

Related

Using MaterialDesignThemes DrawerHost

Please could someone assist me in trying to figure this out.
I have created a menu on a WPF page called DashView.xaml
this menu has buttons on it going down and I would like to know how to get the BottomDrawerContent to be visible once I click on a button.
Below I have given the code that is in DashView.xaml
<materialDesign:DialogHost x:Name="hostSales" >
<materialDesign:DrawerHost x:Name="SalesDrawerHost" Content="Sales" Foreground="GhostWhite"
FontWeight="Bold" FontSize="22" BottomDrawerCloseOnClickAway="True"
Cursor="Hand" Width="200" Height="30" ToggleButton.Checked="chkSalesBt1">
<materialDesign:DrawerHost.BottomDrawerContent x:Uid="dashSalesBt1">
<StackPanel x:Name="stkSalesBt1">
<Button Content="Record Sales" Foreground="GhostWhite" FontWeight="SemiBold"/>
<Button Content="Recent Sales" Foreground="GhostWhite" FontWeight="SemiBold"/>
</StackPanel>
</materialDesign:DrawerHost.BottomDrawerContent>
</materialDesign:DrawerHost>
</materialDesign:DialogHost>
I do have a class called DashClass.cs
Just not sure what I am meant to put in it or how I am meant to get the execution to show the BottomDrawerContent
Yout need a tooglebutton:
<ToggleButton
x:Name="menuToggler"
Style="{DynamicResource MaterialDesignHamburgerToggleButton}" />`
and in the DrawerHost use IsLeftDrawerOpen
<materialDesign:DrawerHost
x:Name="SalesDrawerHost"
Content="Sales"
Foreground="GhostWhite"
FontWeight="Bold"
FontSize="22"
BottomDrawerCloseOnClickAway="True"
Cursor="Hand"
Width="200"
Height="30"
IsBottomDrawerOpen="{Binding ElementName=menuToggler, Path=IsChecked}">
<materialDesign:DrawerHost.BottomDrawerContent x:Uid="dashSalesBt1">
<StackPanel x:Name="stkSalesBt1">
<Button Content="Record Sales" Foreground="GhostWhite" FontWeight="SemiBold"/>
<Button Content="Recent Sales" Foreground="GhostWhite" FontWeight="SemiBold"/>
</StackPanel>
</materialDesign:DrawerHost.BottomDrawerContent>
</materialDesign:DrawerHost>

How to be able to have a two line text on Button content WPF ? And be able to click on text and activate Button1_click

The code is shown below. When I try to click on the middle of the button you are actually clicking the TextBlock and not triggering the Button2_click event. Only if you click outside of the TextBlock and still inside of the Button it would trigger the event.
What is the right way of having a two line text inside the content of the Button.I'm a new on StackOverFlow so I don't have enough reputation to add a picture. Please some Help with this question. Thanks for the Help in Advance.
<Button Content="" Height="77" HorizontalAlignment="Left" Margin="70,136,0,0" Name="Button2" VerticalAlignment="Top" Width="202" />
<TextBlock TextAlignment="Center" Padding="2" Margin="80,152,0,135" FontSize="16" HorizontalAlignment="Left" Width="181" TextWrapping="NoWrap" Foreground="#FF8787DB" FontWeight="Bold"> Calculate CTR Losses<LineBreak></LineBreak> (From FTD Data)</TextBlock>
Put your TextBlock inside your button:
<Button HorizontalAlignment="Left" Margin="70,136,0,0" Name="Button2" VerticalAlignment="Top">
<TextBlock Padding="2" FontSize="16" TextWrapping="NoWrap" Foreground="#FF8787DB" FontWeight="Bold">
Calculate CTR Losses
<LineBreak />
(From FTD Data)
</TextBlock>
</Button>
This will implicitly set Button.Content, it's an equivalent of:
<Button HorizontalAlignment="Left" Margin="70,136,0,0" Name="Button2" VerticalAlignment="Top">
<Button.Content>
<TextBlock Padding="2" FontSize="16" TextWrapping="NoWrap" Foreground="#FF8787DB" FontWeight="Bold">
Calculate CTR Losses
<LineBreak />
(From FTD Data)
</TextBlock>
</Button.Content>
</Button>
Your original code overlays the TextBlock over the button, so both of these elements aren't related.

TabIndex property is not working in Windows Phone 8 application

I am setting the TabIndex propertry inside the Grid.
My code is `
<Grid Margin="30,12" Grid.Row="1" Grid.Column="1" Background="White">
<TextBlock Foreground="#FF858585" Grid.Row="1" Grid.Column="0" Text="{Binding Path=LocalizedResources.Password, Source={StaticResource LocalizedStrings}}"
Padding="10,8" x:Name="tb_pwd" />
<PasswordBox TabIndex="1" Password="" Background="Transparent" BorderBrush="#FF1ba1e2"
Style="{StaticResource PwdBoxStyle}" Grid.Row="1" MaxLength="15" GotFocus="txtpwd_GotFocus_1" LostFocus="txtpwd_LostFocus_1" x:Name="txtpwd">
</PasswordBox>
</Grid>
<Grid Grid.Row="2" Grid.Column="1" Margin="30,0" Background="White">
<TextBlock Foreground="#FF858585" Grid.Row="2" Grid.Column="0" Text="{Binding Path=LocalizedResources.Domain, Source={StaticResource LocalizedStrings}}"
Padding="10,8" x:Name="tb_domain" />
<TextBox TabIndex="2" Text="" Background="Transparent" BorderBrush="#FF1ba1e2"
Style="{StaticResource TxtBoxStyle}"
Grid.Row="2" GotFocus="txtdomain_GotFocus_1"
LostFocus="txtdomain_LostFocus_1"
Grid.Column="1" x:Name="txtdomain" MaxLength="15" />
</Grid>`
But in emulator when i write username and click tab it does not work.
Any suggestions?
The SIP (keyboard) on windows phone does not include a tab key and so there is not support internally for this.
The de-facto convention in apps is to advance the tab focus from code when the user presses the enter key.
There are lots of resources online that show how to do this and helper classes to make it really simple.

Adding and editing item in datagrid with same controls

Hei,
I'm using MVVM with my wpf application. I have DataGrid what shows list of items and i have binded SelectedItem to CurrentSequence propery in my ViewModel. When CurrentSequence changes properties of that object are shown in other controls for editing.
Heres my xaml:
<DataGrid AutoGenerateColumns="False" ItemsSource="{Binding Path=ColorSettingsSequences}"
SelectedItem="{Binding Path=CurrentSequence, Mode=TwoWay}">
.... more things here ...
</DataGrid>
<StackPanel Grid.Column="0" Grid.Row="0">
<Grid>
<Label Content="Start temperature (°C)" Height="28" HorizontalAlignment="Left" x:Name="lblSeqStartTemp" VerticalAlignment="Top" />
<TextBox Height="23" Margin="0,28,10,0" x:Name="tbSeqStartTemp" VerticalAlignment="Top" Text="{Binding Path=CurrentSequence.StartTemp}" />
</Grid>
<Grid>
<Label Content="Start color" Height="28" HorizontalAlignment="Left" x:Name="lblSeqHue" VerticalAlignment="Top" />
<xctk:ColorPicker Margin="0,28,10,0" x:Name="clrpSeqHue" SelectedColor="{Binding Path=CurrentSequence.StartHue, Converter={StaticResource hueToColor}, ConverterParameter=False}" ShowStandardColors="False" />
</Grid>
</StackPanel>
<StackPanel Grid.Column="1" Grid.Row="0">
<Grid>
<Label Content="End temperature (°C)" Height="28" HorizontalAlignment="Left" x:Name="lblSeqEndTemp" VerticalAlignment="Top" />
<TextBox Height="23" Margin="0,28,10,0" x:Name="tbSeqEndTemp" VerticalAlignment="Top" Text="{Binding Path=CurrentSequence.EndTemp}" />
</Grid>
<Grid>
<Label Content="End color" Height="28" HorizontalAlignment="Left" x:Name="lblSeqEndHue" VerticalAlignment="Top" />
<xctk:ColorPicker Margin="0,28,10,0" x:Name="clrpSeqEndHue" SelectedColor="{Binding Path=CurrentSequence.EndHue, Converter={StaticResource hueToColor}, ConverterParameter=False}" ShowStandardColors="False" />
</Grid>
</StackPanel>
Code:
private ColorSettingsSequencesSequence _currentSequence;
public ColorSettingsSequencesSequence CurrentSequence
{
get
{
return this._currentSequence;
}
set
{
this._currentSequence = value;
OnPropertyChanged("CurrentSequence");
}
}
Now the questions is, how could i add a button what would save changes or add a totally new item. I know how to do one or another, but what about 2 together with same controls...
You can create a property on your view model which is of type ColorSettingsSequencesSequence named CurrentSequenceEdit and you can set the value of this object upon changing selection.
Then upon click of an add button you can create a new ColorSettingsSequencesSequence object and set it to the value of CurrentSequenceEdit.
Typically on a new object you'll have an ID that is not set or is set to a negative number which you can use in the Save command to determine whether it needs added to the grid or not.

changing textblock to textbox loses data bindings -

this is a wpf/c# app - I have one grid where I used text boxes and the data bindings were fine. I later built another grid using textblocks. both worked well. but when I changed the textblocks in the second grid into textboxes, all but one stopped displaying data.
I copied both the c# LINQ code and the XAML code that provide the data for the bindings, recompiled, saved it to NotePad++, and closed VS(8). After reopening the project, I reinserted the code, but I still got no data.
Any ideas that would help would be greatly appreciated.
Here's the c# code
var vendDetail = from v in dbC.Vendors
where v.VendorID == vendorid
select new
{
v.Address1,
v.Address2,
CSZ = v.City + ", " + v.State + " " + v.Zip,
v.Phone,
v.Fax,
v.Contact,
v.Terms,
v.eMail
};
grVendorData.DataContext = vendDetail;
And the XAML code:
<TextBox x:Name="txtVendorAddr1"
Text="{Binding Path= Address1}"
Background="AliceBlue"
Grid.Row="2"
Grid.Column="1"/>
<TextBox x:Name="txtVendorAddr2"
Text="{Binding Path= Address2}"
Grid.Row="3"
Grid.Column="1"
Background="AliceBlue"/>
<Label Content="City"
Grid.Row="4"
Grid.Column="0"/>
<TextBox x:Name="txtVendorCity"
Text="{Binding Path= CSZ}"
Grid.Row="4"
Grid.Column="1"/>
<Label Content="Phone"
Grid.Row="1"
Grid.Column="0"/>
<TextBox x:Name="txtVendorPhone"
Text="{Binding Path = Phone}"
Grid.Row="1"
Grid.Column="1"/>
<Label Content="Fax"
Grid.Column="2"
/>
<TextBox Text="{Binding Path = Fax}"
Grid.Row="0"
Grid.Column="3" />
<Label Content="Terms"
Grid.Row="2"
Grid.Column="2"/>
<TextBox Text="{Binding Path = Terms}"
Grid.Row="2"
Grid.Column="3"/>
<Label Content="Notes"
Grid.Row="3"
Grid.Column="2" />
<TextBox Text="{Binding Path = Notes}"
Grid.Row="3"
Grid.Column="3"
Grid.RowSpan="2"
TextWrapping="WrapWithOverflow" />
<Label Content="eMail"
Grid.Row="1"
Grid.Column="2" />
<TextBox Text="{Binding Path = eMail}"
Grid.Row="1"
Grid.Column="3"/>
You cannot bind to anonymous types, which is why the binding worked after you began selecting the whole record.

Categories

Resources