Actually I wanna bind the content part of radio button into the tool tip's radio button
i am a beginer in xaml so jus for practice i want to learn it...for better practice of Data Binding.. my code is as follows :
<Button Name="BtnDemo" Height="Auto" Width="Auto" Content="Hello Dear!" HorizontalAlignment="Left" VerticalAlignment="Top" >
<Button.ToolTip>
<ToolTip >
<StackPanel >
<TextBlock Name="txbDemo" FontWeight="SemiBold" Foreground="Brown" Text="Tool Tip Of Hello Button"/>
<TextBlock Text="This Is The Tool Tip Of Hello Button...!"/>
<RadioButton Content="{Binding Content,ElementName=BtnDemo,UpdateSourceTrigger=Default}" IsChecked="True"/>
</StackPanel>
</ToolTip>
</Button.ToolTip>
</Button>
i wanna do it without c# or VB.net...
Thanx In Advance....
Try this:
<Button Name="BtnDemo" Height="Auto" Width="Auto" Content="Hello Dear!" HorizontalAlignment="Left" VerticalAlignment="Top" >
<Button.ToolTip>
<ToolTip DataContext="{Binding Path=PlacementTarget, RelativeSource={RelativeSource Self}}" >
<StackPanel >
<TextBlock Name="txbDemo" FontWeight="SemiBold" Foreground="Brown" Text="Tool Tip Of Hello Button"/>
<TextBlock Text="This Is The Tool Tip Of Hello Button...!"/>
<RadioButton Content="{Binding Path=Content}" IsChecked="True"/>
</StackPanel>
</ToolTip>
</Button.ToolTip>
</Button>
Related
I have a toolbar in my WPF window as shown in bellow, please help me change labels foreground color dynamically in code behind.
Thanks...
<DockPanel Height="60" VerticalAlignment="Top">
<ToolBar Name="MyToolBar" DockPanel.Dock="Top" Height="60" VerticalAlignment="Top" FlowDirection="RightToLeft"
FontFamily="Calibri" FontSize="16" FontWeight="Bold" Background="#FFEEF5FD" Foreground="Black" ScrollViewer.VerticalScrollBarVisibility="Disabled">
<Button Name="BtnSubmit" Style="{DynamicResource TStyle}" Click="BtnSubmit_Click" Tag="New" Height="52" Width="60"
IsDefault="True" Margin="0,0,0,1">
<StackPanel Margin="0" Height="54"
<Image Source="/Img/Save 04.png" Height="25" Margin="16,0"/>
<Label Content="Save" Margin="0,0,0,0" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"
HorizontalAlignment="Center" VerticalAlignment="Center"/>
</StackPanel>
</Button>
<Button Name="BtnApply" Style="{DynamicResource TStyle}" Click="BtnApply_Click" Tag="New" Height="52"
IsDefault="True" Margin="0,1,0,2" Width="85">
<StackPanel Margin="0" Height="52" Width="82">
<Image Source="/Img/ApplyIcon.png" Height="25" Margin="29,0,26,0"/>
<Label Content="Edit" Margin="-15,0,-23,0" HorizontalContentAlignment="Center" VerticalContentAlignment="Center"
HorizontalAlignment="Center" VerticalAlignment="Center"/>
</StackPanel>
</Button>
</ToolBar>
</DockPanel>
To change the Foreground of all TextBlock elements you must define a Brush resource and assign it to all relevant TextBlock elements using {DynamicResource}:
MainWindow.xaml
<Window>
<Window.Resources>
<SolidColorBrush x:Key="ButtonLabelForegroundBrush" Color="Black" />
</Window.Resources>
<DockPanel>
<ToolBar>
<Button>
<TextBlock Foreground="{DynamicResource ButtonLabelForegroundBrush}" />
</Button>
</ToolBar>
</DockPanel>
</Window>
MainWindow.xaml.cs
private void ChangeTextBlockForeground()
{
var brush = FindResource("ButtonLabelForegroundBrush") as SolidColorBrush;
brush.Color = Colors.Red;
}
In this code I added an image before the button text I'd like to have a space between the image and text but the code I have isn't working.
<Button Height="25"
Width="80"
Margin="5,10,5,10"
Command="{Binding PreviewTemplateCommand}">
<StackPanel Orientation="Horizontal" Height="15" Width="63">
<Image Source="/UILibrary;component/Themes/Default/Images/preview.PNG"
Height="15" Width="15" Margin="0,0,0,0" />
<TextBlock >Preview</TextBlock>
</StackPanel>
</Button>
Hi you have to set the left margin of the textblock. Try this:
<StackPanel Orientation="Horizontal" Height="15" Width="63">
<Image Source="..." Height="15" Width="15" Margin="0,0,0,0" />
<TextBlock Margin="25,0,0,0">Preview</TextBlock>
</StackPanel>
I'm doing a list in my project, that needs a button for each item.
How can I get those buttons in ListBox, like in the page "Last calls" of my windows phone?
Thanks.
FunksMaName answer is very much correct except a Small change.....
<ListBox Height="360"
HorizontalAlignment="Left"
Margin="22,23,0,0"
Name="UserDetailsListBox"
VerticalAlignment="Top"
Width="413"> <ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Button.Template>
<ControlTemplate>
<Image Source="/Assets/Images/MyImage.png" />
</ControlTemplate>
</Button.Template>
<TextBlock x:Name="txtOverViewHeader1"
Text="OverView"
Foreground="Yellow"
Width="600"
FontSize="28"
Margin="10,0,0,0"
Height="65">
</TextBlock>
</StackPanel>
</DataTemplate></ListBox.ItemTemplate></ListBox>
i just moved image inside button's template instead of content ... That is more accurate..
We may add button for each item of the Listbox like this.
<ListBox Height="360"
HorizontalAlignment="Left"
Margin="22,23,0,0"
Name="UserDetailsListBox"
VerticalAlignment="Top"
Width="413">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Vertical"
>
<StackPanel Orientation="Horizontal">
<Button Width="150" Height="50" x:Name="Btn1" Content="Button1" Margin="0,-20,0,0"/>
<TextBlock x:Name="txtOverViewHeader1"
Text="OverView"
Foreground="Yellow"
Width="600"
FontSize="28"
Margin="10,0,0,0"
Height="65">
</TextBlock>
</StackPanel>
<StackPanel Orientation="Horizontal">
<Button Width="150" Height="50" x:Name="Btn2" Content="Button2" Margin="0,-20,0,0"/>
<TextBlock x:Name="txtOverViewHeader2"
Text="OverView"
Foreground="Yellow"
Width="600"
FontSize="28"
Margin="10,0,0,0"
Height="65">
</TextBlock>
</StackPanel>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
Hope it will give you the desired answer
The easiest way to get round buttons is to user Coding4Fun. It is free to use and very simple to install.
You can follow these instructions to use it in your application.
As for the icons, you can either search around for some free packs or you can see if Metro Studio 2 has the icon you need. That tool is also free to use.
Use a circular image, and set the Tap event, or wrap your image around a Button template if you need a buttons specific behavior
<ListBox Height="360"
HorizontalAlignment="Left"
Margin="22,23,0,0"
Name="UserDetailsListBox"
VerticalAlignment="Top"
Width="413">
<ListBox.ItemTemplate>
<DataTemplate>
<StackPanel Orientation="Horizontal">
<Button Template="x:Null" Tap="">
<Image Source="/Assets/Images/MyImage.png" />
</Button>
<TextBlock x:Name="txtOverViewHeader1"
Text="OverView"
Foreground="Yellow"
Width="600"
FontSize="28"
Margin="10,0,0,0"
Height="65">
</TextBlock>
</StackPanel>
</DataTemplate>
</ListBox.ItemTemplate>
</ListBox>
I tried to implement case in which one TextBlock appears on top of another TextBlock, playing with Visibility property - but it doesn't working yet.
TextBlock are inside DockPanel:
<DockPanel Grid.Row="1" Margin="5">
<TextBlock Text="Text1" Height="20" HorizontalAlignment="Right" DockPanel.Dock="Right">
<TextBlock Text="Text2" Background="Aqua" HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Visibility="{Binding IfDeviceSelected, NotifyOnSourceUpdated=True, Converter={StaticResource ResourceKey=BoolToVisibilityConverter}}" />
</TextBlock>
<TextBlock Text="#Device Focus:" Height="20" HorizontalAlignment="Right" DockPanel.Dock="Right" />
</DockPanel>
You will want to use a Grid to group these TextBlocks, DockPanel/StackPanel will not allow overlapping controls(without horrible manipulation of Margins etc)
<DockPanel Grid.Row="1" Margin="5" >
<Grid DockPanel.Dock="Right" >
<TextBlock Text="Text1" />
<TextBlock Text="Text2" Background="Aqua" Visibility="{Binding IfDeviceSelected, NotifyOnSourceUpdated=True, Converter={StaticResource ResourceKey=BoolToVisibilityConverter}}" />
</Grid>
<TextBlock Text="#Device Focus:" Height="20" HorizontalAlignment="Right" DockPanel.Dock="Right" />
</DockPanel>
I have a Toolbar whose ItemSource is a collection of toolbarItems which contain the bitmap text and other info for the button and the xaml includes a DataTemplate to bind the data to the button.
Our app now needs to become 508 compliant and when I run the Accessible Event Watcher it is listing all the toolbar button names as "Unknown".
Can someone tell me how to provide a meaningful name to the buttons?
Here's the portion of xaml applying to this issue:
<ToolBar.ItemTemplate>
<DataTemplate DataType="{x:Type src:toolBarItem}">
<DataTemplate.Resources>
<src:toolBarItemConverter x:Key="buttonConverter" />
<src:booleanToVisibilityConverter x:Key="boolToVisibilityConverter" />
<src:toolBarButtonFormatConverter x:Key="toolBarFormatDisplayConverter" />
<src:stringToVisibilityConverter x:Key="stringToVisibilityDisplayConverter" />
</DataTemplate.Resources>
<StackPanel Orientation="Horizontal">
<Border Style="{StaticResource SeparatorStyle}" Visibility="{Binding menuSeparator, Converter={StaticResource boolToVisibilityConverter}}"/>
<Button x:Name="listButton" Height="{Binding menuHeight, Mode=OneWay}" Width="{Binding menuWidth}" VerticalAlignment="Top" HorizontalAlignment="Center" Visibility="{Binding isActiveButton, Converter={StaticResource boolToVisibilityConverter}}" Tag="{Binding}"
ToolTip="{Binding menuTooltip}" IsEnabled="{Binding isEnabled}" >
<UniformGrid VerticalAlignment="Center" HorizontalAlignment="Center" Rows="{Binding menuText,Converter={StaticResource toolBarFormatDisplayConverter}}" >
<!-- button image -->
<Image Grid.Row="0" HorizontalAlignment="Center" VerticalAlignment="Center" Source="{Binding menuImage, Converter={StaticResource buttonConverter}}"/>
<!-- button name -->
<Viewbox StretchDirection="DownOnly" HorizontalAlignment="Center" VerticalAlignment="Bottom" Visibility="{Binding menuText, Converter={StaticResource stringToVisibilityDisplayConverter}}" >
<TextBlock x:Name="buttonName" FontFamily="Segoe UI" Width="{Binding menuWidth}" FontSize="12" Grid.Row="1" TextAlignment="Center" TextWrapping="Wrap" HorizontalAlignment="Center" VerticalAlignment="Bottom" Text="{Binding menuText}" Foreground="Black" />
</Viewbox>
</UniformGrid>
<!-- </StackPanel> -->
</Button>
</StackPanel>
</DataTemplate>
</ToolBar.ItemTemplate>
Thanks,
Ron
OK we figured this out. Need to simply bind your names to the AutomationProperties.Name
<Button x:Name="listButton" AutomationProperties.Name="{Binding menuText}"
Height="{Binding menuHeight, Mode=OneWay}" Width="{Binding menuWidth}"
VerticalAlignment="Top" HorizontalAlignment="Center"
Visibility="{Binding isActiveButton,
Converter={StaticResource boolToVisibilityConverter}}"
Tag="{Binding}" ToolTip="{Binding menuTooltip}" IsEnabled="{Binding isEnabled}" >