I want to change placeholder text in Combo Box in winRT development - winrt-xaml

I want the foregroud color of Placeholder is Foreground="#ffae19". But i get it in black color.
Can any one have solution for this :-)
<ComboBox x:Name="selectLanguage" Background="#5d198e" Foreground="#ffae19" PlaceholderText=" SELECT LANGUAGE" Width="280" Height="40" HorizontalAlignment="Center" VerticalAlignment="Center" DropDownOpened="selectLanguage_Click">
<ComboBox.ItemTemplate>
<DataTemplate>
<Grid Background="#5d198e" Width="280" Height="40">
<TextBlock Foreground="#ffae19" HorizontalAlignment="Center" VerticalAlignment="Center" Text="{Binding languageName}" ></TextBlock>
</Grid>
</DataTemplate>
</ComboBox.ItemTemplate>
</ComboBox>

You can override these default resource keys to set the color of the placeholder text without retemplating the control:
<StaticResource x:Key="ComboBoxPlaceHolderForeground" ResourceKey="SystemControlPageTextBaseHighBrush" />
<StaticResource x:Key="ComboBoxPlaceHolderForegroundFocusedPressed" ResourceKey="SystemControlHighlightAltBaseHighBrush" />

You have to edit the default styles of he combobox. Use blend for that, right click on the combobox->edit style. you will get the default style. Look out for placeholder style, and change it accordingly.

Related

[UWP][VisualState] Custom ListViewItem hover presentation

I would like to add hover actions to a ListViewItem, but it seems that in the ListViewItem.DataTemplate the "PointerOver" state is not triggered.
I was creating a custom ItemContainerStyle but in this style, I can just set specific properties related to the TargetType 'ListViewItem'. In my case, I would like to have a button which is only visible, when the user hover over the item.
I want to use the VisualStateManager, but maybe I havn´t understood the concept behind styles, templates and user interaction with bindings in between.
Are there good references/documentation for this?
Thank you in advance
[UWP][VisualState] Custom ListViewItem hover presentation
For your requirement, the better way is
XamlBehaviors to edit the property witin DataTempate. For the detail please refer the following code.
<ListView x:Name="MyListView">
<ListView.ItemTemplate>
<DataTemplate>
<Grid Name="GridPanel">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="auto" />
<ColumnDefinition Width="auto" />
</Grid.ColumnDefinitions>
<TextBlock x:Name="InfoTextBlock" Text="{Binding}" />
<TextBlock
x:Name="FlagTextBlock"
Grid.Column="1"
Text="Hover"
Visibility="Collapsed"
>
<Interactivity:Interaction.Behaviors>
<Interactions:EventTriggerBehavior EventName="PointerEntered" SourceObject="{Binding ElementName=GridPanel}">
<Interactions:ChangePropertyAction
PropertyName="Visibility"
TargetObject="{Binding ElementName=FlagTextBlock}"
Value="Visible"
/>
<Interactions:ChangePropertyAction
PropertyName="Foreground"
TargetObject="{Binding ElementName=InfoTextBlock}"
Value="Red"
/>
</Interactions:EventTriggerBehavior>
<Interactions:EventTriggerBehavior EventName="PointerExited" SourceObject="{Binding ElementName=GridPanel}">
<Interactions:ChangePropertyAction
PropertyName="Visibility"
TargetObject="{Binding ElementName=FlagTextBlock}"
Value="Collapsed"
/>
<Interactions:ChangePropertyAction
PropertyName="Foreground"
TargetObject="{Binding ElementName=InfoTextBlock}"
Value="Black"
/>
</Interactions:EventTriggerBehavior>
</Interactivity:Interaction.Behaviors>
</TextBlock>
</Grid>
</DataTemplate>
</ListView.ItemTemplate>
<x:String>Hello Test</x:String>
<x:String>Hello Test</x:String>
<x:String>Hello Test</x:String>
</ListView>

Putting an ItemContainerStyle on a Grid

Obviously ItemContainerStyle doesn't exist in a Grid, which is the problem.
My program has a ListView that displays a bunch of projects. I want to add a button to each project that gives more info, and that much I can do easily. The problem I'm encountering is the border that appears on each project, which is toggled on/off by clicking the project to show the user which are currently selected. I don't want this border to encircle my button; I want the button placed to the right of the bit with the border.
I can't put the button on a separate list or I'll get two different scroll-able lists, so it must stay within the ListView, but any border on the ListView will encircle everything in the ListView. My solution was to make a StackPanel with two Grids inside the ListView, where the first Grid has all of my old stuff and the toggle-able border and the second grid only has my button. So now I just need to move that border onto the Grid... but how?
XAML code:
<!-- Other code up above... -->
<ListView x:Name="lstAvailableProjects"
Grid.Row="1"
ItemsSource="{Binding ProjectList, Mode=TwoWay}"
Height="Auto"
Width="Auto"
SelectionMode="Multiple"
IsRightTapEnabled="True"
IsDoubleTapEnabled="False"
IsSwipeEnabled="False"
SelectionChanged="lstAvailableProjects_SelectionChanged"
Background="Transparent"
VerticalAlignment="Top"
ItemContainerStyle="{StaticResource ActiveProjectListViewStyle}"
BorderThickness="30,0,0,0">
<ListView.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Grid HorizontalAlignment="Stretch" Width="250" Background="{Binding Converter={StaticResource projectStateColorConverter}}">
<Grid.RowDefinitions>
<RowDefinition/>
<RowDefinition/>
</Grid.RowDefinitions>
<TextBlock Text="{Binding ProjectName}"
Foreground="Black"
Margin="10 5 0 0"
FontSize="17"
VerticalAlignment="Center"
Grid.Row="0"
HorizontalAlignment="Stretch"/>
<TextBlock Text="{Binding AssignmentRole}"
Visibility="{Binding ProjectAssignmentRole, Mode=OneWay, Converter={StaticResource visibilityConverter}}"
Foreground="Black"
Margin="10 3 0 5"
FontSize="14"
Grid.Row="1"
HorizontalAlignment="Stretch"/>
<TextBlock Text="{Binding StatusText}"
Foreground="Red"
Margin="10 3 0 5"
Grid.Row="2"
FontSize="14"/>
</Grid>
<Grid>
<Button>
<Button.Template>
<ControlTemplate>
<Image Source="../Assets/setting_icon.png" Height="40" />
</ControlTemplate>
</Button.Template>
</Button>
</Grid>
</StackPanel>
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
Since the grid items are wrapped You cannot make changes in xaml to achieve it other than overriding the preparecontainerforitemoverride.
A little tricky hack would be to apply transform to the button.
<Button.RenderTransform>
<CompositeTransform TranslateX="100" TranslateY="100"/>
<Button.RenderTransform>

How to access elements in cellTemplate of a datagrid Column

I have a datagrid in which columns are added dynamically and their celltemplate is also set in code behind.
</UserControl.Resources>
<DataTemplate x:Key="GridDataTemplate">
<Grid x:Name="mainGrid">
<TextBlock Text="{Binding Index}"/>
</Grid>
</DataTemplate>
</UserControl.Resources>
<Grid x:Name="LayoutRoot" HorizontalAlignment="Center" VerticalAlignment="Center" Background="White">
<sdk:DataGrid AutoGenerateColumns="False" x:Name="dataGrid" />
</Grid>
In code behind -
DataGridTemplateColumn col = new DataGridTemplateColumn() { CellTemplate = Resources["GridDataTemplate"] as DataTemplate };
dataGrid.Columns.Add(col);
Now what I want is to access the grid that is a part of cell template so that I can set its DataContext but I am not able to do so. I have tried using col.CellTemplate.LoadContent() to get the grid but it only gives the grid but I cannot set the datacontext of grid using this.
Can anyone please suggest how can this be done??

wpf calling particular array item from button

I have a Movie class with a Dim _characters = New ObservableCollection(of String)
In my MainWindow.vb i have,
Dim movies = New ObservableCollection(of Movie)
Me.parentG.DataContext = Me.movies
i want to add characters to the movie based on button click at runtime.
How can i get the particaular movie for which the character button was clicked?
MainWindow.xaml:-
<Grid Name="parentG" >
<ItemsControl ItemsSource="{Binding}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid>
<Grid.ColumnDefinitions>
<ColumnDefinition Width="100"></ColumnDefinition>
<ColumnDefinition Width="100"></ColumnDefinition>
<ColumnDefinition Width="700"></ColumnDefinition>
</Grid.ColumnDefinitions>
<TextBox Grid.Column="0" Text="{Binding MovieName}" />
<Button Grid.Column="1" Content="New Character" Click="newCharacterButton_Click" Height="20" Width="100" HorizontalAlignment="Left" />
<ListBox Grid.Column="2" Name="cList" ItemsSource="{Binding Characters}">
<ListBox.ItemTemplate >
<DataTemplate >
<TextBox Text="{Binding Name}"/>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
</Grid>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
</Grid>
finally figured it out. Below are the steps :-
in the button handler, convert sender to Button
get its parent, in my case it was the Grid
Get the DataContext of the Grid, convert it to (in this case), Movie
Get index of this Movie in the Movie array, assuming an index property existed for each Movie, and was set during initialization.
Add a character to this movie

change button to his binding color when pressed

i want to change my button color when is pressed :
<DataTemplate>
<!--Click="btn_Click"-->
<ItemsControl DataContext="{Binding}" ItemsSource="{Binding}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Button
Name="btn"
DataContext="{Binding}"
Height="65" Width="79"
Background="Gray"
>
<Button.Template>
<ControlTemplate TargetType="{x:Type Button}">
<Ellipse Name="elipse1" Height="65" Width="79" Fill="{Binding Path=ButtonColor}" Visibility="Collapsed"></Ellipse>
<ControlTemplate.Triggers>
<Trigger Property="IsPressed" Value="True">
<Setter TargetName="elipse1" Property="Visibility" Value="Visible"/>
</Trigger>
</ControlTemplate.Triggers>
</ControlTemplate>
</Button.Template>
</Button>
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
it doesnt seem to work farther then that wjen i use the all triger <> the gray button is not showen has if this template is stronger then the binding ?is it true ? how to outcome it ?
The problem is that when the button isn't pressed - it has no visual impact (Visibility="Collapsed") - there are no elements inside the Button - thus it becomes invisible (and then it is hard to Press it :)).
You need to put something besides the Ellipse in the ControlTemplate to have it show something instead of the ellipse.

Resources