'ToolTip' cannot have a logical or visual parent - wpf-controls

I have the following problem. I keep getting 'ToolTip' cannot have a logical or visual parent error when i try to style tooltip for the toggle button. What went wrong? When i take out the tooltip control under ToggleButton.ToolTip it works !
<ToggleButton x:Name="toggle" OverridesDefaultStyle="True" Template="{StaticResource ExpanderToggleButton}" Margin="0,4,0,0" VerticalAlignment="Top" IsChecked="{Binding IsExpanded, Mode=TwoWay, RelativeSource={RelativeSource TemplatedParent}}">
<ToggleButton.ToolTip>
<ToolTip Style="{StaticResource tooltipstyle}">
<TextBlock Background="Transparent"/>
</ToolTip>
</ToggleButton.ToolTip>
</ToggleButton>

If you write code like this using property element syntax, you call already the constructor of the ToolTip class.
<ToggleButton.ToolTip>
<TextBlock></TextBlock>
</ToggleButton.ToolTip>
There is no need to instantiate another ToolTip inside like this...
<ToggleButton.ToolTip>
<ToolTip Style="{StaticResource tooltipstyle}">
<TextBlock Background="Transparent"/>
</ToolTip>
</ToggleButton.ToolTip>
Besides, on my system (using .NET 4.5) there is no error.
It seems that WPF can handle both versions meanwhile as intended by the developer.

Related

Xamarin ListView Issue

I am beginer on Xamarin. What did I do wrong here. I am trying to add Conext Menu to ListView and compiler is not happy with this.
<ListView x:Name="VehicleList">
<ListView.ItemTemplate>
<DataTemplate>
<ImageCell
ImageSource="152x152#1x.png"
Text="{Binding Title}"
Detail="{Binding SubTitle}"
TextColor="#f35e20"
DetailColor="#503026" />
<!-- adding this caused error
<ViewCell>
<ViewCell.ContextActions>
<MenuItem Clicked="OnDelete" CommandParameter="{Binding .}"
Text="Archive"
IsDestructive="True" />
</ViewCell.ContextActions>
</ViewCell>
-->
</DataTemplate>
</ListView.ItemTemplate>
</ListView>
You are defining two viewcells in one data template. this is not possible!
You should create a DataTemplateSelector and declare the ViewCells in separate classes. Then you can make the selector choose a viewcell based on the logic implemented in the DataTemplateSelector. The xamarin documentation has a nice explanation: https://developer.xamarin.com/guides/xamarin-forms/application-fundamentals/templates/data-templates/selector/

Any idea to create masked text box in uwp

Currently I got a requirement to implement a control something like traditional masked text box. But unfortunately there is no first party control (some third party paid control is available like Component 1) available in uwp. If anybody has any idea to create the same please share.
You can make a TextBox background transparent and have a TextBlock behind it with your watermark text. Bind the visibility to the TextBox Text.IsEmpty property using a BooleanToVisibilityConverter
<Grid Grid.Row="0" Margin="5" Background="White">
<TextBlock VerticalAlignment="Center" Margin="3"
Foreground="SteelBlue"
Visibility="{Binding ElementName=MyTextBox, Path=Text.IsEmpty, Converter={StaticResource BooleanToVisibilityConverter}}">Type in here...</TextBlock>
<TextBox Background="Transparent"
x:Name="MyTextBox"/>
</Grid>
In your resources:
<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
Have a look at PlaceHolderText Property on TextBox control.

The button is not visible

I have a UWP application, I have added a button but when I debug the application, I can't see the button. If I add a texblock or textBox I can see them, but not the button.
I have set IsEnabled to true and visibility to visible but I am not able to solve the problem.
Also I have tried to click in the place where it should be the button but nothing happens.
This happens when I debug in local machine and when I debug in a emulator of windows phone 10.
Thank you so much.
EDIT: the axml code
<Page
x:Class="SqliteEF7UWP.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:SqliteEF7UWP"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d">
<Grid Background="Transparent">
<Button x:Name="GetVideos" IsEnabled="True" Visibility="Visible" Background="Aquamarine" Content="Buscar Videos" HorizontalAlignment="Left" Margin="120,98,0,510" VerticalAlignment="Stretch" Click="button_Click"/>
<TextBlock x:Name="textBlock" Foreground="BlueViolet" HorizontalAlignment="Left" Margin="101,59,0,0" TextWrapping="Wrap" Text="TextBlock" VerticalAlignment="Top" Height="34" Width="132"/>
<TextBox x:Name="textBox" HorizontalAlignment="Left" Margin="213,59,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top"/>
</Grid>
</Page>
The margin you set for the Button is too aggressive. The object is now "squeezed". For example set Margin to "120,98,0,200" (or simply "120,98") instead of "120,98,0,510" and it should be visible.
BTW using hardcoded margins to setup the user interface is probably not a good idea. Use for example the Grid with columns and rows instead of margins.

How to clone UIElement in Silverlight

Can anybody tell me how to clone UIElement in SILVERLIGHT ?. I dug a lot in the google but I'm not able to find relevant solution, everywhere I'm just getting solution to clone UIElement in WPF, however same is not applicable in the Silverlight.
I need to add the a UIElement in the same grid's next rows on click of a + button eachtime.
Plz help..any answer will be appreciable
Thanks
GK
There is no facility to do that.
In your scenario you can use an ItemsControl (directly or as a ListBox, for example) and provide your to-be-duplicated piece of UI as a datatemplate:
<ItemsControl ItemsSource="{Binding MyData}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<Grid>
<TextBlock Text="{Binding LabelText}" />
</Grid>
<DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>
This is the most typical way of doing it, but you will need to know about databinding to do it.
There is also the possibility of factoring out your to-be-duplicated piece of UI in a UserControl and add that programmatically multiple times.

WPF window template resource

I am trying to define a window template that can be used by windows in other assemblies. I define a window template and store it in resource dictionary in some assembly. After, I use this template in other assembly on window definition in XAML. It looks that the template is accepted and I can see updated window in VS-2010 designer but when I add a new control to this window, the control disappears from window but still exists in XAML code. I also tried to apply the same template explicitly and it works well.
Xaml code of generic.xaml in project that contains template definition, the ThemeInfo attribute is set and BuildAction property for this file is Page.
<ControlTemplate x:Key="{ComponentResourceKey TypeInTargetAssembly= {x:Type local:DialogResources}, ResourceId=DialogTemplate}">
<Border Width="Auto" Height="Auto" Name="windowFrame"
BorderBrush="#395984"
BorderThickness="1"
CornerRadius="0,20,20,20"
Background="AliceBlue">
<Grid>
<Grid.RowDefinitions>
<RowDefinition Height="Auto"></RowDefinition>
<RowDefinition></RowDefinition>
</Grid.RowDefinitions>
<TextBlock Margin="1" Padding="5" Text="Template Window" FontWeight="Bold"/>
<Border Background="#B5CBEF" Grid.Row="1" CornerRadius="0,0,20,20" >
<AdornerDecorator>
<ContentPresenter/>
</AdornerDecorator>
</Border>
</Grid>
</Border>
</ControlTemplate>
DialogRespources - is an empty class that defined in MyProg.Resources assembly.
Now I use this template in other assembly like this:
In this window I add a button but I can't to see it. When I define the TemplateControl explicitly (without using resource) I can see it.
The other problem is that I get a following designer exception when use TargetType="{x:Type Window}" for template in resource: "'Window' ControlTemplate TargetType does not match templated type 'WindowInstance'." I could not find anything regarding this exception in Google.
Please, help me to understand what is wrong in my code?

Resources