issue in watermark textbox - c#

I am new to wpf.I downloaded the wpf toolkit and then added it's dll file into my project file.Then tried some code to create watermark textbox but showing error(The tag 'WatermarkTextBox' does not exist in XML namespace).
<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
x:Class="TRAINING.WaterMark"
x:Name="Window"
Title="WaterMark"
Width="640" Height="480">
<extToolkit:WatermarkTextBox>
<extToolkit:WatermarkTextBox.Watermark>
<StackPanel Orientation="Horizontal">
<Image Source="Contact16.png" Stretch="None" />
<TextBlock Text="Enter First Name" Margin="4,0,0,0" />
</StackPanel>
</extToolkit:WatermarkTextBox.Watermark>
</extToolkit:WatermarkTextBox>
</Window>
Please help.

I have not used the wpf toolkit before, but I'm pretty sure that as you have added the namespace using xctk, then you should use that in the xaml - i.e. xctk:WatermarkTextBox instead of extToolkit:WatermarkTextbox

<Window
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:extToolkit="http://schemas.microsoft.com/winfx/2006/xaml/presentation/toolkit/extended"
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
x:Class="TRAINING.WaterMark"
x:Name="Window"
Title="WaterMark"
Width="640" Height="480">
<extToolkit:WatermarkTextBox>
<extToolkit:WatermarkTextBox.Watermark>
<StackPanel Orientation="Horizontal">
<Image Source="Contact16.png" Stretch="None" />
<TextBlock Text="Enter First Name" Margin="4,0,0,0" />
</StackPanel>
</extToolkit:WatermarkTextBox.Watermark>
</extToolkit:WatermarkTextBox>
</Window>
I Guess You Missed the refrence of that extToolkit so i added. i hope it will help you

My reason for this issue was confusion between xceed ($) vs dotnetprojects (Free) NuGet package.
So once I uninstalled the xceed, everything was working fine and error was resolved.

Related

Image is blank when program is run

When I add an image from my WPF project and use a resource for the source, it looks ok in the designer:
Main window in designer
My code is:
<Window x:Class="WpfPlay.MainWindow"
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"
xmlns:local="clr-namespace:WpfPlay"
mc:Ignorable="d"
Title="MainWindow" Height="271.107" Width="392.316">
<Grid>
<Image x:Name="image" HorizontalAlignment="Left" Height="128" Margin="22,22,0,0" VerticalAlignment="Top" Width="342" Source="pack://siteoforigin:,,,/Resources/logo.jpg" />
<TextBox x:Name="textBox" HorizontalAlignment="Left" Height="23" Margin="137,185,0,0" TextWrapping="Wrap" Text="TextBox" VerticalAlignment="Top" Width="120"/>
</Grid>
However I find that when I run the program, although the text box can be seen, the image is blank.
#Clemens has the correct answer - set the build action of the image file to resource
file properties
Just to add useful hint to #Clemens comment: if your logo.jpg file included in the same project as control, then after typing Source="pack://application:,,,/ you can press Ctrl+Space, and visual studio would show you a helper message about what file you can reference.

MVVM Light namespace issue - Code compiles fine but no preview of the controls in the XAML file

Any idea what's wrong with the following (MVVM Light) code. It compiles fine but for some reason I cannot see a preview of the controls and I see a squiggly line in the EventToCommand (<GalaSoft_MvvmLight_Command:EventToCommand see picture below) but it seems to have the right namespace.
Any idea how can I fix it? Or this is simply the behavior expected when using MVVM Light?
FYI - Found a few similar questions about namespacing issues but my seem to be different since the code compiles fine.
<Window x:Class="MvvmControlChange.Content.MainPage.View.MainPageView"
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"
xmlns:GalaSoft_MvvmLight_Command="clr-namespace:GalaSoft.MvvmLight.Command;assembly=GalaSoft.MvvmLight.Extras.WPF4"
xmlns:Custom="clr-namespace:System.Windows.Interactivity;assembly=System.Windows.Interactivity"
xmlns:ignore="http://www.ignore.com"
mc:Ignorable="d ignore"
DataContext="{Binding MainPageViewModel,
Source={StaticResource Locator}}"
Title="Give me Liberty or Give me Smart Basic"
d:DesignHeight="360"
d:DesignWidth="488"
SizeToContent="WidthAndHeight">
<Button x:Name="Page2Button"
Content="Page 2"
Margin="0"
Grid.Row="1"
d:LayoutOverrides="Width, Height"
HorizontalAlignment="Center"
VerticalAlignment="Center">
<Custom:Interaction.Triggers>
<Custom:EventTrigger EventName="Click">
<GalaSoft_MvvmLight_Command:EventToCommand x:Name="Page2ButtonClicked"Command="{Binding Page2Command, Mode=OneWay}" />
</Custom:EventTrigger>
</Custom:Interaction.Triggers>
</Button>
</Window>
Squiggly Line:
Reference Files:
For the record, here is the answer to my question.
https://blogs.msdn.microsoft.com/brada/2009/12/11/visual-studio-project-sample-loading-error-assembly-could-not-be-loaded-and-will-be-ignored-could-not-load-file-or-assembly-or-one-of-its-dependencies-operation-is-not-supported-exception-from/

Is there a way to display WPF Extended Toolkit's control in VS Designer?

I'm used to create my forms with the designer, and modifying the XAML manually only when needed.
Even though the extended toolkit is a fantastic library, it still lacks integration with Visual Studio's designer. Can, by any mean, the toolkit's controls be displayed in the designer (not the toolbox), like standard controls? And if not, is there an explanation?
For now, the toolkit's controls are just blank and unselectable with simple clicks.
NOTE: It seems that the issue happens with container components (like BusyIndicator and Wizard/WizardPage) only.
EDIT: Here's some of my XAML. With this, I can see the wizard's first page, but no obvious way to see the others. If I put my Wizard in a BusyIndicator, can't see a thing at all.
<Window x:Class="MyProgram.MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="clr-namespace:MyProgram"
xmlns:xctk="http://schemas.xceed.com/wpf/xaml/toolkit"
Title="My Program" Height="477" Width="688" MinWidth="688" MinHeight="478">
<xctk:Wizard x:Name="wizard" FinishButtonClosesWindow="True" Next="wizard_Next">
<xctk:WizardPage Name="Intro_Page" Title="ABC" Description="abc" NextPage="{Binding ElementName=Second_Page}" Enter="disallowNext">
<xctk:WizardPage.Content>
<Grid>
<Label Content="abc" HorizontalAlignment="Center" Margin="0,54,0,87" Name="intro_lbl" VerticalAlignment="Center" Grid.Column="1" Padding="5" HorizontalContentAlignment="Center" Height="28" IsEnabled="False" />
</Grid>
</xctk:WizardPage.Content>
</xctk:WizardPage>
<xctk:WizardPage Name="Second_Page" Title="DFG" Description="dfg" NextPage="{Binding ElementName=Last_Page}">
<xctk:WizardPage.Content>
<Grid Name="grid">
<TextBox Grid.Column="1" Height="23" HorizontalAlignment="Stretch" Name="txt_second" VerticalAlignment="Center" />
</Grid>
</xctk:WizardPage.Content>
</xctk:WizardPage>
<xctk:WizardPage Name="Last_Page" PageType="Interior"
Title="Last Page"
Description="This is the last page in the process"
CanFinish="True" />
</xctk:Wizard>
</Window>
I know this answer comes late, but yesterday I was stumbling myself over this problem and maybe it is useful for others who land here.
I solved it by creating an own control derived from WizardPage.
Just Create a new UserControl, include the Xceed.Wpf.Toolkit namespace and change the Type from UserControl to xctk:WizardPage in the xaml file as well as in the code-behind file.
<xctk:WizardPage x:Class="WizardTest.MyWizardPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:xctk="clr-namespace:Xceed.Wpf.Toolkit;assembly=Xceed.Wpf.Toolkit"
xmlns:local="clr-namespace:WizardTest"
mc:Ignorable="d"
d:DesignHeight="300" d:DesignWidth="300">
<Grid>
<TextBlock>Hello World!</TextBlock>
</Grid>
</xctk:WizardPage>
Now you can create your UI using the VisualStudio Designer.
To place your page in the wizard, simply put an object of you derived page into its items:
<xctk:Wizard>
<local:MyWizardPage Title="My Wizard Page"/>
</xctk:Wizard>
You can use Bindungs in your costum page out of the box because DataContext of the MyWizardPage object is set automatically to the wizards DataContext (which inherits from the Window DataContext if not explicitly given)

Error template not showing for controls within a page

I have a textbox within a page that binds to a model property that is validated, and when there is an error the error template is not shown!
A few points:
I have no validation issues for controls in there own window (not within a page displayed in a frame within a window).
The error template works, it is displayed for controls within a window.
The model is validating because the "Save" button within the page is disabled when a validation error is identified.
I "think" the problem lies with the fact that the control is within a page that is hosted within frame and thus the data context is not being passed to the page as it is seemingly isolated. Could that be the case? and if so how do I go about fixing this issue? and if not what else could it be?
The code (I have of course simplified the code to isolate the issue):
<Page x:Class="PIRS_Client.View.Staff.StaffDetailsView"
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"
xmlns:ignore="http://www.ignore.com"
mc:Ignorable="d ignore"
DataContext="{Binding StaffDetailsVM, Source={StaticResource Locator}}"
Height="576" Width="1163">
<Grid>
<TextBox HorizontalAlignment="Left" Text="{Binding Model.title, ValidatesOnDataErrors=True}" Height="17" Margin="284,453,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="90"/>
<Button Content="Save Changes" Command="{Binding SaveDetailsCommand}" IsEnabled="{Binding Model.IsValid}" HorizontalAlignment="Left" Margin="1007,518,0,0" VerticalAlignment="Top" Width="104" Height="23"/>
</Grid>
If I can add any further information or code please just let me know!
Problem solved - it transpires that Windows have a built in adorner layer but Pages do not, I would love to give you a detailed explanation as to why not but I don't know why (read below). But the solution is that you need to wrap your page contents in an adorner decorator to provide them with an adorner layer.
Just to be clear here is the "fixed" code:
<Page x:Class="PIRS_Client.View.Staff.StaffDetailsView"
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"
xmlns:ignore="http://www.ignore.com"
mc:Ignorable="d ignore"
DataContext="{Binding StaffDetailsVM, Source={StaticResource Locator}}"
Height="576" Width="1163">
<AdornerDecorator>
<Grid>
<TextBox HorizontalAlignment="Left" Text="{Binding Model.title, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=True}" Height="17" Margin="284,453,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="90"/>
<Button Content="Save Changes" Command="{Binding SaveDetailsCommand}" IsEnabled="{Binding Model.IsValid}" HorizontalAlignment="Left" Margin="1007,518,0,0" VerticalAlignment="Top" Width="104" Height="23"/>
</Grid>
</AdornerDecorator>
If you know why pages don't implement the adorner layer and can provide a more insightful answer please feel free to add an explanation as another answer which contains the solution i.e. this and the explanation and I will change your answer to be the correct answer (instead of mine) - just to promote sharing knowledge ;)

moonlight vs. silverlight :: datagrid incompatibility?

I'm trying to develop an application in moonlight. Now I'm trying to use a DataGrid to show some data.
In an old silverlight project I used a DataGrid in this way:
<UserControl x:Class="One.Page"
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"
d:DesignHeight="300" d:DesignWidth="400"
xmlns:my="clr-namespace:System.Windows.Controls;assembly=System.Windows.Controls.Data">
<Grid x:Name="LayoutRoot" Background="White">
<StackPanel Orientation="Vertical">
<TextBlock x:Name="lbl1">lblInfo1</TextBlock>
<TextBlock x:Name="lbl2">lblInfo2</TextBlock>
<TextBox x:Name="txt1">Write here</TextBox>
<Button x:Name="btn1" Content="Send" Click="btn1_Click" />
<my:DataGrid x:Name="grData"
Grid.Row="1"
Width="500" Height="250"
Margin="10"
AutoGenerateColumns="False">
<my:DataGrid.Columns>
<my:DataGridTextColumn Header="Código" />
<my:DataGridTextColumn Header="Lote" />
<my:DataGridTextColumn Header="Ciudad" />
<my:DataGridTextColumn Header="País" />
</my:DataGrid.Columns>
</my:DataGrid>
</StackPanel>
</Grid>
</UserControl>
but if I use the same code in my new moonlight project I get an empty page. I've been looking for some examples and I found a simple one:
http://geeks.ms/blogs/lmblanco/archive/2008/09/02/silverlight-datagrid-crear-una-columna-a-partir-de-varios-valores.aspx
Is this example the writer use the DartaGrid in the same way than me. Can anyone explain me why in VS2010 I can use this code and In monodevelop 2.4 or monodevelop 2.8 I can't?
According to some research on Google, it looks like your project needs additional dependencies and MonoDevelop isn't notifying you: http://mono.1490590.n4.nabble.com/Moonlight-datagrid-support-td1836948.html

Categories