Questions when customize the header of a pivotitem - silverlight

try to customize the header of each PivotItem, i google first and write code below, this is OK:
<controls:Pivot Title="MyPivot">
<!--Pivot item one-->
<controls:PivotItem>
<controls:PivotItem.Header>
<TextBlock Text="Pivot1" FontSize="40"/>
</controls:PivotItem.Header>
<Grid/>
</controls:PivotItem>
</controls:Pivot>
when I add the second pivot item in this way, an error appears as "Value does not fall within the expected range.",the error starts from [controls:PivotItem] of "pivot item two",
<controls:Pivot Title="MyPivot">
<!--Pivot item one-->
<controls:PivotItem>
<controls:PivotItem.Header>
<TextBlock Text="Pivot1" FontSize="40"/>
</controls:PivotItem.Header>
<Grid/>
</controls:PivotItem>
<!--Pivot item two-->
<controls:PivotItem>
<controls:PivotItem.Header>
<TextBlock Text="Pivot2" FontSize="40"/>
</controls:PivotItem.Header>
<Grid/>
</controls:PivotItem>
</controls:Pivot>
When I build the project, the error just gone away, and the whole app runs like a charm.
But everytime i add a new pivot item in this way, the error shows up.
My questions are:
why does this error happen and how to solve it?
can I ignore this error?

This "error" is thrown just at design-time, and I think you can ignore it. Also, it will go definitively away the first time you build the project (so it means there are no real problems in your project, and also no warnings)!
There are more of this type of errors thrown by the designer.
Ignore it!

Related

How to prevent the dragablz tabs of being reordered by the user?

I want to disable the option of reordering tabs using the dragablz tabs.
How can I do it?
As you can see in the attached code, I have removed the TabablzControl.InterTabController, and it helped me with the problem of dragging tabs out of a window into a new one. But I also need to prevent changing their order, and I have no clue how to do that.
<Grid Margin="0,0,2,0">
<dragablz:TabablzControl Margin="8" TabStripPlacement="Left" AllowDrop="False" >
<!--if you want to allow dragging tabs out of the window into a new window (loke googke Chrome) then uncomment next lines.-->
<!--<dragablz:TabablzControl.InterTabController>
<dragablz:InterTabController/>
</dragablz:TabablzControl.InterTabController>-->
<TabItem Header="Tab No. 1" IsSelected="True">
<TextBlock>Hello World</TextBlock>
</TabItem>
<TabItem Header="Tab No. 2">
<TextBlock>We Have Tearable Tabs!</TextBlock>
</TabItem>
</dragablz:TabablzControl>
</Grid>
Ok, I have figured it out. In the second line add an attribute FixedHeaderCount.
This attribute gets as value the number of tabs that you want to be fixed.
So If you have 3 tabs, and you want them all to be fixed the second line should look like that:
<dragablz:TabablzControl Margin="8" TabStripPlacement="Left" AllowDrop="False" FixedHeaderCount="3">

Copy pasting things in xaml auto-indents?

This is something that has bothered me for some time, and I'm not sure if it's some setting that can be turned off or not, but whenever I copy and paste something in xaml in VS 2010 it always auto-indents the line that I'm on and often the one after it for some reason. For example, say I have these lines of xaml code:
<TextBlock VerticalAlignment="Top" Foreground="Red" FontSize="11" Width="5"
Text="*" Visibility="{Binding Path=ShowInvalidFlag,UpdateSourceTrigger=PropertyChanged}" />
<TextBlock Width="Auto" Background="Transparent" Text="{Binding Path=QuestionValue}" />
and then I realize that the first TextBlock needs a Margin defined and I copy Margin="0,1,0,0" from another control within the same xaml document and paste it within the declaration of the above TextBlock it auto-indents and I end up with this:
<TextBlock VerticalAlignment="Top" Margin="0,1,0,0" Foreground="Red" FontSize="11" Width="5"
Text="*" Visibility="{Binding Path=ShowInvalidFlag,UpdateSourceTrigger=PropertyChanged}" />
<TextBlock Width="Auto" Background="Transparent" Text="{Binding Path=QuestionValue}" />
Why is it doing this? It doesn't even have to be copied from the same xaml file or even xaml code (I just tried copying random text from a text file and pasted it within the control and it still auto-indented). It's quite frustrating that every time I paste something in xaml I need to re-adjust my indentation.
Converted from comment:
If you search in the options in VS you should be able to find under Text Editor and Xaml an option for Indenting. By default it's set to "smart" which isn't always as smart as you might want it to be. Play around with that and see if it's more comfortable for you. Copy / pasting seems to be particularly prone to tripping it up.
In addition, you can also always so to "Edit" -> "Advanced" and then either "Format Document" or "Format Selection" to force Visual Studio to take another pass at formatting which may either fix, or make worse, your problem.
I think the problem is that it tries to optimize between speed and correctness. When you paste something it may not consider the entire context of where you are pasting and instead only look at the immediate parent and / or siblings which is a problem when you are pasting in a whole bunch of stuff.

WPF: Tab GroupBox item appears and disappears after cleaning & building

Using VS2012 and .NET 4.0, I have the following block of code in a UserControl:
<GroupBox Name="LocalGroup">
<GroupBox.Header>
<TextBlock FontWeight="Bold"
Text="Local Rules">
</TextBlock>
</GroupBox.Header>
<StackPanel Margin="20,8,10,0"
Orientation="Vertical" >
<local:LocalRulesHeader />
</StackPanel>
</GroupBox>
When I build the program the line '' gets the blue squiggly underline with the error message of
Error 16 The component 'ToolLibrary.LocalRulesHeader' does not have a resource
identified by the URI '/ToolLibrary;component/xamlclasses/localrulesheader.xaml'.
Yet when I clean the project the blue squiggly line disappears and the LocalRulesHeader is displayed in the GroupBox as expected. I do a build and the blue squiggly line and error message reappear.
I have tried cleaning the project as well as shutting down VS and restarting to no avail.
Has anyone experienced this and found a way to resolve?

Navigating to a different assembly in Silverlight

I'm trying to navigate to a page located in a different assembly with no success.
I made an extremely simple Silverlight Navigation Application make my point:
I simply have a Hyperlink with:
NavigateUri="/PageClassLibrary;component/Pages/PageInLibrary.xaml"
In the calling page (MainPage.xaml in MainNavigationApp) I have a Frame with no UriMappings for now.
<Grid x:Name="LayoutRoot">
<navigation:Frame x:Name="ContentFrame"
Style="{StaticResource ContentFrameStyle}"
Navigated="ContentFrame_Navigated"
NavigationFailed="ContentFrame_NavigationFailed">
</navigation:Frame>
<Grid x:Name="NavigationGrid" Style="{StaticResource NavigationGridStyle}">
<StackPanel x:Name="LinksStackPanel" Style="{StaticResource LinksStackPanelStyle}">
<HyperlinkButton x:Name="Link3"
Style="{StaticResource LinkStyle}"
NavigateUri="/PageClassLibrary;component/Pages/PageInLibrary.xaml"
TargetName="ContentFrame"
Content="page in a class library" />
</StackPanel>
</Grid>
</Grid>
But when I run it, I get an error message saying that the page was not found:
Page not found: "/PageClassLibrary;component/Pages/PageInLibrary.xaml"
I even modified MainNavigationApp dependencies, checking depends on PageClassLibrary, but it didn't improve the outcome.
I ran out of ideas. Does anybody have a hint?
Here's thesolution:
https://skydrive.live.com/#cid=B79120F33F3A7A64&id=B79120F33F3A7A64%21105
AAAhhh!, the solution was there in front of my eyes. JUST ADD A REFERENCE TO THE ASSEMBLY. dah!

Silverlight: "The name already exists in the tree"

this is a problem that regularly arises when I write Silverlight XAML. In this case, I've made a usercontrol VerticalTabStop (code attached) that has a ToolTip attached. I instanciate a couple of my usercontrols, and then I get the debugging window and the following error:
Line:52
Error: Unhandled Error in Silverlight 2 Application
Code: 2028
Category: ParserError
Message: The name already exists in the tree: AltLabel.
File:
Line: 0
Position: 0
I get an awful lot of these messages as I hover my mouse over the buttons. Any suggestions to what I'm doing wrong here?
Cheers
Nik
<UserControl
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
x:Class="SLEntityPresenterWebPart.VerticalTabStop"
d:DesignWidth="20" d:DesignHeight="27">
<Grid x:Name="LayoutRoot">
<StackPanel>
<Canvas x:Name="TabStopCanvas" Height="27" Width="20">
<ToolTipService.ToolTip>
<TextBlock x:Name="AltLabel" Text="Substitute me"/>
</ToolTipService.ToolTip>
<Image x:Name="IconImg" Canvas.Left="7" Canvas.Top="9" Width="26" Height="26" Source="Contact.png" Canvas.ZIndex="5" Margin="0,-9,0,0" RenderTransformOrigin="0.5,0.5">
<Image.RenderTransform>
<TransformGroup>
<ScaleTransform ScaleX="0.85" ScaleY="0.85"/>
<SkewTransform/>
<RotateTransform/>
<TranslateTransform X="0"/>
</TransformGroup>
</Image.RenderTransform>
</Image>
<Image Source="stop.png" Margin="3,0,0,0"/>
</Canvas>
</StackPanel>
</Grid>
</UserControl>
There is very similar bug even in Silverlight 4.
If you create custom usercontrol, usually:
<UserControl xmlns:MyNameSpace="clr-namespace:MyNameSpace" x:Class="MyNameSpace.MyClass"
x:Name="userControl" ... />
Then, if you add 2 controls without names to the xaml code (with preview):
<MyNameSpace:MyClass ... />
<MyNameSpace:MyClass ... />
There will be exception "The name already exists in the tree: userControl". It occurs because Silverlight can't find the name (unnamed [MyClass]) and looks to the UserControl where it finds "userControl" twice.
One of the solution is to give some names to the controls:
<MyNameSpace:MyClass x:Name = "MyControl1" ... />
Or initialize this control from code:
MyClass control = new MyClass();
SomeGrid.Children.Add(control);
This is a bug in Silvelight. The way to work around it is to remove the Name attribute on the TextBlock in the Tooltip.
I presume that you have the name there for a reason, and that not being able to refer to this element from code is going to be a problem for you. As a work around for that, try replacing the tooltip xaml with this:
<ToolTipService.ToolTip>
<ToolTip x:Name="AltLabel" Content="Substitute me" />
</ToolTipService.ToolTip>
Now you can get to the text by doing AltLabel.Content.
If this does not solve your problem, please let me know.
I was struggling with the same message yesterday...
ParserError - The name already exists in the tree: blah
In my case the problem was that somehow a reference was added... to itself. (The DLL of the project in the projects own bin/debug folder). Removing this reference sorted out the problem.
Seems that this error message is too vague.
Try to remove any name like ' x:Name="TabStopCanvas" ' in stack panel, it worked for me.

Resources