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

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?

Related

Inline Run objects not completely highlighted when a hyphen is present

I've got this really weird problem where I'm doing highlighting on certain parts of text on a TextBlock object containing multiple Run objects.
<TextBlock Name="InlineTextBlock" Background="White">
<Run Foreground="White"
Background="Blue"
FontSize="75"
FontFamily="Helvetica">17-Oct-13</Run>
<Run Foreground="White"
Background="Blue"
FontSize="75"
FontFamily="Helvetica">17/Oct/13</Run>
</TextBlock>
It's pretty straightforward code to read, and from reading, you would expect both 17-Oct-13 and 17/Oct/13 to be completely highlighted with a Blue Background and White Foreground.
The odd thing is, the hyphen character has 1 pixel on the left and the right where the Background color is not being applied.
There are no issues with highlighting for the second Run object with 17/Oct/13.
Would appreciate any help to figure out this odd problem.
EDIT:
Running this on my computer displays the following (you'll have to look really closely to see it):
Also, I noticed this only occurs on certain fonts like Helvetica, Arial, Consolas (to name a few). Verdana seems to display fine.
Unfortunately, running your code on my computer does not suffer from this problem:
I'm guessing that you have something else causing your problem.
For your information, I'm running Visual Studio 2010 on Windows 7 and .NET 4.0.
UPDATE >>>
Thanks for the update... I can now confirm that I see your mysterious vertical white lines around the hyphens using the Helvetica font. I can't imagine what is causing it, but assuming that you can't set the main TextBlock.Background to Blue, you can still fix this issue by using an inner TextBlock with its Background set to Blue:
<TextBlock Name="InlineTextBlock" Background="White">
<TextBlock Background="Blue">
<Run Foreground="White"
Background="Blue"
FontSize="50"
FontFamily="Helvetica">17-Oct-13</Run>
<Run Foreground="White"
Background="Blue"
FontSize="50"
FontFamily="Helvetica">17/Oct/13</Run>
</TextBlock>
</TextBlock>

error when adding image to wpf toolbar button

I am getting this error: "value does not fall within the expected range" when I try to add code to add an image for a button in a wpf app in VB.net. I don't seem to know what to do or what is wrong? Here is the XAML code that gives the error:
<ToolBarTray Height="33" Name="ToolBarTray1" VerticalAlignment="Top">
<ToolBar Background="Cyan" Height="33" Band="1" BandIndex="1" ToolBarTray.IsLocked="True">
<Button><Image Source="new.bmp"/></Button>
</ToolBar>
</ToolBarTray>
The part that is underlined showing the error is <Image Source="new.bmp"/> . Someone tell me what is not right.
I'm not sure how your project is set up but read this http://msdn.microsoft.com/en-us/library/aa970069.aspx

Questions when customize the header of a pivotitem

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!

Allow SmithHtmlEditor for Spell Check

I'm using the SmithHtmlEditor and it is working fine but we've had the request to add spell checking that is native to WPF <TextBox SpellCheck.IsEnabled=True /> I've simply tried adding that line to the TextBox in the control but I'm not getting the squiggly line and the context menu with suggestions, maybe b/c the WindowsFormsHost. I'm open to changing controls as well.
<Grid>
<TextBox x:Name="CodeEditor"
AcceptsReturn="True"
AcceptsTab="True"
AutoWordSelection="True"
VerticalScrollBarVisibility="Auto"
TextWrapping="Wrap"
SpellCheck.IsEnabled="True"/>
<WindowsFormsHost x:Name="BrowserHost">
<wf:WebBrowser x:Name="VisualEditor" />
</WindowsFormsHost>
</Grid>
This enables spell check to the text editor only. If you go to code mode you will see that spell check is enabled there but only there.
The WebBrowser is WinForms component and you can't add spellcheck in that way.

Bizarre problem with WPF XAML file

I've just started a very simple WPF application which consists of a main large image and four smaller images.
In order to assist with the layout, I created some JPEGs in MsPaint containing the images -2, -1, 0, +1 and +2 and just copied them into the top level of the project directory.
The XAML segment contains, for the five images:
<Image Grid.Column="1" Grid.Row="2" Grid.ColumnSpan="4" Grid.RowSpan="1"
Margin="0,0,0,0" Name="imgPicture" Stretch="Fill" VerticalAlignment="Top"
Source="file:///C:/DAndS/Pax/MyDocs/VS2008/Projects/MyProj/zero.jpg" />
<Image Grid.Column="1" Grid.Row="4" Grid.ColumnSpan="1" Grid.RowSpan="1"
Margin="0,0,0,0" Name="imgPicMinus2" Stretch="Fill" VerticalAlignment="Top"
Source="file:///C:/DAndS/Pax/MyDocs/VS2008/Projects/MyProj/minus2.jpg" />
<Image Grid.Column="2" Grid.Row="4" Grid.ColumnSpan="1" Grid.RowSpan="1"
Margin="0,0,0,0" Name="imgPicMinus1" Stretch="Fill" VerticalAlignment="Top"
Source="file:///C:/DAndS/Pax/MyDocs/VS2008/Projects/MyProj/minus1.jpg" />
<Image Grid.Column="3" Grid.Row="4" Grid.ColumnSpan="1" Grid.RowSpan="1"
Margin="0,0,0,0" Name="imgPicPlus1" Stretch="Fill" VerticalAlignment="Top"
Source="file:///C:/DAndS/Pax/MyDocs/VS2008/Projects/MyProj/plus1.jpg" />
<Image Grid.Column="4" Grid.Row="4" Grid.ColumnSpan="1" Grid.RowSpan="1"
Margin="0,0,0,0" Name="imgPicPlus2" Stretch="Fill" VerticalAlignment="Top"
Source="file:///C:/DAndS/Pax/MyDocs/VS2008/Projects/MyProj/plus2.jpg" />
When I try to set the source property for the plus2 image, it complains with a dialog box stating:
Property value is not valid.
Details
|
V
The file plus2.jpg is not part of the project or
its 'Build Action' property is not set to 'Resource'.
Yet if I rename the file to plus3.jpg or plus2x.jpg, I don't have that problem.
Why is it complaining about plus2.jpg specifically?
Is it possible that you previously added then removed plus2.jpg?
Is it possible that you have not built the solution between the steps?
Clear src, build solution, set src to known working image, build solution, set src to non-working image.
Clear src of all images, build solution, set "Build Action" of all images to "None", build solution, set build-action to "Resource", build solution, set src of all images.
(Most Likely) Possible corrupted image, image with invalid color palette, image saved in invalid format.
See if you can load the image during run-time
Load image with Resouce Editor and "Save As".
The file extension does not make a difference, because the internal graphics format determines the image type. Meaning, if you created a jpg but saved it as bmp, the designer will still load the image correctly.
Try <Image.Source> <BitmapImage UriSource="sampleImages/bananas.jpg" /> </Image.Source>
I tried to duplicate the problem with no luck. I was able to use images that I "added existing" and images where I specified src="file:///c:..." Images inside the project, with and without the build-action set. Even images outside the project.
My other thought is there is something wrong with the image, but I did not add the comment. Yet, now that I think about it, the designer is going to try and load the image once you set src. If the image cannot be loaded then an exception will be thrown. Since you are in design-time, you get the invalid property prompt with an "obsure" details message.
What if you load the image during run-time to see what kind of exception is thrown, if any.
Don't really care about it. VS2008 when creating WPF applications has dozens of such warnings and most of them disappears after build. If app starts and is working - leave it alone. Personally I've installed around 10-15 hotfixes for various WPF related bugs in VS2008. VS2010 is much better.
Besides it's probably better to include image files in resources - you add them to the project (Add existing item) and then check whether the build action is set to Resource. (right click on that file in Solution Explorer and choose Properties)

Resources