Tab button becomes disabled - c#

I have a C# WPF app where there are some buttons on top to perform functions like table lookup or maintenance here:
<Border Grid.Row="0" CornerRadius="5" BorderBrush="AliceBlue" Margin="10" VerticalAlignment="Top" >
<StackPanel Orientation="Horizontal" Height="35" >
<Button Content="Upload File" Margin="0,0,3,0" Command="{Binding CmdUploadFileCtrl}" Width="100"></Button>
<Button Content="Medicine Price" Margin="0,0,3,0" Command="{Binding CmdMedicinePriceCtrl}" Width="100"></Button>
<Button Content="NDC Discounts" Margin="0,0,3,0" Command="{Binding CmdNDCDiscountCtrl}" Width="100"></Button>
<Button Content="Facility" Margin="0,0,3,0" Command="{Binding CmdFacilityCtrl}" Width="100"></Button>
</StackPanel>
</Border>
<sdk:DataGrid
Grid.Row="1" x:Name="dgFacility"
SelectionMode="Single"
SelectedItem="{Binding Path=SelectedItemFacility, Mode=TwoWay}"
ItemsSource="{Binding Path=LstFacility, Mode=TwoWay}"
AutoGenerateColumns="False"
HorizontalAlignment="Stretch"
VerticalAlignment="Stretch"
AllowDrop="False">
When user presses Facility tab it goes there, but when then tried to 'Upload file' that button is become disabled. How can I prevent this disabling?

Since the buttons are bound to commands, there should be code (somewhere) that is determining when the buttons are enabled/disabled.
Depending on what type of commanding is being used you may have a method named something like CanUploadFileCtrl or CmdUploadFileCtrl_CanExecute which returns true/false.

Related

Unable to reorder items in GridView when WrapPanel is used UWP

And am creating a sorting app and in some cases i will hide the gridview item and i encountered the same error as this person:
Hide GridViewItem and reposition items in GridView
So I implemented the fix and it worked, but it suddenly disallowed be to drag and reorder items in my GridView.And from what I can tell it only appeared after I implemented the WrapPanel into my gridView.ItemsPanel and by removing it I am immediately able to reorder again.
and here's my XML code:
<Page
x:Class="ImageSorting.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:ImageSorting"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:data ="using:ImageSorting.Models"
xmlns:toolkit="using:WinRTXamlToolkit.Controls"
mc:Ignorable="d">
<Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
<Grid HorizontalAlignment="Stretch" Height="57" VerticalAlignment="Top">
<Border BorderBrush="Black" BorderThickness="0 0 0 1" HorizontalAlignment="Stretch" Height="57" VerticalAlignment="Top"/>
<Button x:Name="SelectFolder" Content="Select Folder" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,11,10,0" Background="#80a4ec" Click="SelectFolder_Click"/>
<Button x:Name="AddFolder" Content="Add Folder" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,11,125,0" Background="#84eeb1" Click="AddFolder_Click" />
<Button x:Name="Save" Content="Save" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,11,230,0" Background="#ece880" Click="Save_Click"/>
<ComboBox x:Name="ImageFolder" HorizontalAlignment="Left" VerticalAlignment="Top" Margin=" 20 11 0 0" SelectedIndex="0" SelectionChanged="ImageFolder_SelectionChanged">
<ComboBoxItem>All Images</ComboBoxItem>
</ComboBox>
</Grid>
<GridView x:Name="ImageGrid" HorizontalAlignment="Stretch" Margin="10,60,10,0" VerticalAlignment="Stretch" ItemsSource="{x:Bind ImgList, Mode=OneWay}" CanDragItems="True" AllowDrop="True" CanReorderItems="True" SelectionMode="Extended">
<GridView.ItemTemplate>
<DataTemplate x:DataType="data:Images">
<StackPanel>
<Image x:Name="Image" Width="206" Height="158" Source="{x:Bind imageData}" DoubleTapped="Image_DoubleTapped"/>
<StackPanel Orientation="Horizontal">
<TextBlock HorizontalAlignment="Left" FontSize="15" Text="{x:Bind imageNumber}" Margin="10 5 0 0"/>
<TextBlock HorizontalAlignment="Left" TextAlignment="Left" Width="100" FontSize="15" Text="{x:Bind altChar}" Margin="10 5 0 0"/>
<CheckBox x:Name="altNumber" HorizontalAlignment="Right" MinWidth="0" Margin="35 0 0 0" Click="altNumber_Click"/>
</StackPanel>
</StackPanel>
</DataTemplate>
</GridView.ItemTemplate>
<GridView.ItemsPanel>
<ItemsPanelTemplate>
<toolkit:WrapPanel Orientation="Horizontal" AllowDrop="True">
</toolkit:WrapPanel>
</ItemsPanelTemplate>
</GridView.ItemsPanel>
</GridView>
<Grid x:Name="ConfirmGrid" HorizontalAlignment="Stretch" Height="50" VerticalAlignment="Bottom" Background="White" Visibility="Collapsed">
<Border BorderBrush="Black" BorderThickness="0 1 0 0" HorizontalAlignment="Stretch" Height="57" VerticalAlignment="Top" />
<Button x:Name="FolderConfirm" Content="Confirm" HorizontalAlignment="Right" VerticalAlignment="Top" Margin="0,10,10,0" RenderTransformOrigin="-0.128,7.104" Click="FolderConfirm_Click" />
</Grid>
</Grid>
Image of when i try to drag and reorder GridView's Item with WrapPanel:
Am I missing something that is stated in the WinRTXamlToolkit, or there no way around this problem.
UPDATE 2017 Nov 27
So after some tinkering as suggested by # Xavier Xie - MSFT so try implement the drag and drop to reorder feature for winRT toolkit by inheriting the WrapPanel class and trying it from there.
Here's what I have found out so far,
winRT toolkit WrapPanel inherits Panel class
WrapPanel from other libraries like UWPCommunityToolkit
also inherits Panel hence making me thing that all Dynamic Wrapping needs to inherit the Panel class.
Panel class doesn't have any code for detecting item drag event (either that or I am dragging the wrong thing)
ItemsWrapPanel is a seal class making it impossible for me to inherit and that goes for any Interface it inherits as well
And this is concluded what I have found out so far and will continue to update this if I found anything.
Credits goes to # Xavier Xie - MSFT for pointing me into the right direction for this.
The WrapPanel of WinRTXamlToolkit has not implemented reordering function. You would need to implement the reordering manually, listening to the drag & drop events.
If you want to implement by yourself, you could read Jerry Nixon's blog Walkthrough: Reordering items in a GridView with Drag and Drop to understand the basic principle of GridView's reordering.
As a easy workaround, you could use ItemsStackPanel control as its ItemsPanel, it has implemented reordering function. This control also will not have space item there when you hide one item.

How do you use StackPanel.FindName in WPF?

I have a stack panel with a set of four image buttons inside of it. When I try to search by the name of the image button it comes back null. What is wrong with my code?
XAML:
<StackPanel x:Name="swatchClearStackPanel" Orientation="Vertical" Grid.Column="1" Grid.Row="2" Margin="0,10,0,0" HorizontalAlignment="Left" VerticalAlignment="Bottom">
<imgbutton:ImageButton x:Name="ClearSwatchColor1" Grid.Row="0" Grid.Column="2" Style="{DynamicResource ButtonClearSwatchColor}" Margin="5,8,5,5" HorizontalAlignment="Left" Visibility="Hidden" Click="ClearSwatchColor_Click" />
<imgbutton:ImageButton x:Name="ClearSwatchColor2" Grid.Row="0" Grid.Column="2" Style="{DynamicResource ButtonClearSwatchColor}" Margin="5,18,5,5" HorizontalAlignment="Left" Visibility="Hidden" Click="ClearSwatchColor_Click"/>
<imgbutton:ImageButton x:Name="ClearSwatchColor3" Grid.Row="0" Grid.Column="2" Style="{DynamicResource ButtonClearSwatchColor}" Margin="5,18,5,5" HorizontalAlignment="Left" Visibility="Hidden" Click="ClearSwatchColor_Click"/>
<imgbutton:ImageButton x:Name="ClearSwatchColor4" Grid.Row="0" Grid.Column="2" Style="{DynamicResource ButtonClearSwatchColor}" Margin="5,20,5,5" HorizontalAlignment="Left" Visibility="Hidden" Click="ClearSwatchColor_Click"/>
</StackPanel>
And the C#:
EDIT: Note: The button name is hard coded to show that it cannot find it, the end result will be a variable as its one method that several buttons will reference. This code triggers after the UI has loaded. (The user clicks a button and this code runs. Same window, same everything.)
var swatchClearButton = swatchClearStackPanel.FindName("ClearSwatchColor1");

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.

C# WPF comboBox strange issue

I've two comboBoxes one above another. The problem appear if you open the form that contain this comboBoxes and avoid mouse over at lower comboBox, you just click on first comboBox and from drop down list choose item that is located right over the second comboBox. Once you click on an item the drop down list will close but your mouse will remain over the second comboBox. But this comboBox will not highlight and react on your clicks at all. Take a look at this picture please:
Both comboBoxes IsEditable = false; But if you move your mouse out of the 2nd comboBox and back over to it - everything will works fine. Help me please how to fix this.
UPD. XAML:
<ComboBox Background="{x:Null}" Height="33" HorizontalAlignment="Left" IsEditable="False" IsEnabled="True" Margin="10,151,0,0" Name="comboBox2" VerticalAlignment="Top" Width="239" VerticalContentAlignment="Center" FontSize="14" IsReadOnly="False" Text="" SelectionChanged="comboBox2_SelectionChanged" TabIndex="6" HorizontalContentAlignment="Left" Padding="10,3" FontWeight="SemiBold" AllowDrop="False" Cursor="Hand" IsTabStop="True" />
<ComboBox Background="{x:Null}" FontSize="14" Height="33" HorizontalAlignment="Left" IsEditable="False" IsEnabled="True" Margin="10,190,0,0" Name="comboBox3" VerticalAlignment="Top" VerticalContentAlignment="Center" Width="439" IsReadOnly="False" Text="" SelectionChanged="comboBox3_SelectionChanged" TabIndex="8" HorizontalContentAlignment="Left" Padding="10,3" FontWeight="SemiBold" ClipToBounds="False" Cursor="Hand" IsHitTestVisible="True" SnapsToDevicePixels="True" UseLayoutRounding="True" />
Set Background property to White or Transparent instead of {x:Null}. Null background affects control hit-test behavior.

TextBlock on top of ImageButton (Windows 8 XAML/C#)

Can someone give me an example of how to style a button with XAML hat has three states (hover, normal, pressed). i want the whole area of the button to be covered with an image (one for each of the three different states) and i want text to be on top that also has three different colors for the different states. i have something like this already (without the color states on the textblock). the problem i'm having at this point is that the textblock is blocking the input events for the button undernearth (i also haven't implemented the color changes for the textblock....
current code:
<DataTemplate x:Name="SubjectItemTemplate">
<Canvas Width="225" Height="225">
<Button Canvas.Left="0" Canvas.Top="0"
Command="{Binding ElementName=LayoutRoot, Path=DataContext.NavigateToUnitsPage}"
CommandParameter="{Binding}">
<Button.Template>
<ControlTemplate>
<Grid Background="{Binding LightThemeColor}" Width="205" Height="205">
<controls:ImageButton HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,0,0,0"
NormalStateImageSource="{Binding ImageUriNormal}"
HoverStateImageSource="{Binding ImageUriHover}"
PressedStateImageSource="{Binding ImageUriPressed}" Command="{Binding ElementName=LayoutRoot, Path=DataContext.NavigateToUnitsPage}"
CommandParameter="{Binding}"/>
<TextBlock Text="{Binding Name}" FontSize="18" TextWrapping="Wrap" TextAlignment="Center" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,168,0,0" />
</Grid>
</ControlTemplate>
</Button.Template>
</Button>
</Canvas>
</DataTemplate>
The reason that the ImageButton events are not being handled as expected with the TextBlock is because the TextBlock is located in-line with the ImageButton and not contained inside the ImageButton. To change this, the TextBlock has to be placed inside the ImageButton.
<controls:ImageButton HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,0,0,0"
NormalStateImageSource="{Binding ImageUriNormal}"
HoverStateImageSource="{Binding ImageUriHover}"
PressedStateImageSource="{Binding ImageUriPressed}" Command="{Binding ElementName=LayoutRoot, Path=DataContext.NavigateToUnitsPage}" CommandParameter="{Binding}" >
<TextBlock Text="{Binding Name}" FontSize="18" TextWrapping="Wrap" TextAlignment="Center" HorizontalAlignment="Center" VerticalAlignment="Top" Margin="0,168,0,0" />
</controls:ImageButton>

Categories

Resources