473,396 Members | 2,014 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

can't write in textbox WPF

i made a custom skinned textbox in App.xaml, here's the XAML:
Expand|Select|Wrap|Line Numbers
  1. <Style TargetType="{x:Type TextBox}">
  2.  
  3.             <Setter Property ="Background">
  4.                 <Setter.Value>
  5.                     <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0" MappingMode="RelativeToBoundingBox">
  6.                         <GradientStop Color="#FFF8F8F8" Offset="0.116"/>
  7.                         <GradientStop Color="#FFE8E8E8" Offset="0.672"/>
  8.                         <GradientStop Color="#FFF0F0F0" Offset="0.388"/>
  9.                     </LinearGradientBrush>
  10.                 </Setter.Value>
  11.             </Setter>
  12.  
  13.             <Setter Property="BorderBrush">
  14.                 <Setter.Value>
  15.                     <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
  16.                         <GradientStop Color="#FFD0D0D0" Offset="0.073"/>
  17.                         <GradientStop Color="White" Offset="1"/>
  18.                         <GradientStop Color="#FED4D4D4" Offset="0.366"/>
  19.                         <GradientStop Color="#FED6D6D6" Offset="0.724"/>
  20.                         <GradientStop Color="#FED0D0D0" Offset="0.108"/>
  21.                     </LinearGradientBrush>
  22.                 </Setter.Value>
  23.             </Setter>
  24.  
  25.             <Setter Property="Template">
  26.                 <Setter.Value>
  27.                     <ControlTemplate TargetType="{x:Type TextBox}">
  28.  
  29.                         <Border BorderThickness="1" BorderBrush="{TemplateBinding BorderBrush}" Background="{TemplateBinding Background}"/>
  30.  
  31.                         <ControlTemplate.Triggers>
  32.  
  33.                             <Trigger Property="IsMouseOver" Value="True">
  34.  
  35.                                 <Setter Property="BorderBrush">
  36.                                     <Setter.Value>
  37.                                         <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
  38.                                             <GradientStop Color="#FFA7A7A7" Offset="1"/>
  39.                                             <GradientStop Color="#FFD0D0D0"/>
  40.                                             <GradientStop Color="DarkGray" Offset="0.44"/>
  41.                                         </LinearGradientBrush>
  42.                                     </Setter.Value>
  43.                                 </Setter>
  44.  
  45.                             </Trigger>
  46.  
  47.                             <Trigger Property="IsFocused" Value="True">
  48.  
  49.                                 <Setter Property="Background">
  50.                                     <Setter.Value>
  51.                                         <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0" MappingMode="RelativeToBoundingBox">
  52.                                             <GradientStop Color="#FFF8F8F8"/>
  53.                                             <GradientStop Color="#FFF0F0F0" Offset="0.672"/>
  54.                                             <GradientStop Color="#FFF0F0F0" Offset="0.401"/>
  55.                                         </LinearGradientBrush>
  56.                                     </Setter.Value>
  57.                                 </Setter>
  58.  
  59.                                 <Setter Property="BorderBrush">
  60.                                     <Setter.Value>
  61.                                         <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
  62.                                             <GradientStop Color="#FFD0D0D0" Offset="0.073"/>
  63.                                             <GradientStop Color="#FED0D0D0" Offset="0.909"/>
  64.                                         </LinearGradientBrush>
  65.                                     </Setter.Value>
  66.                                 </Setter>
  67.  
  68.                                 <Setter Property="Effect">
  69.                                     <Setter.Value>
  70.                                         <DropShadowEffect BlurRadius="48" Opacity="0.295" ShadowDepth="3" Color="#FF939393" Direction="191"/>
  71.                                     </Setter.Value>
  72.                                 </Setter>
  73.  
  74.                             </Trigger>
  75.  
  76.                             <Trigger Property="IsEnabled" Value="False">
  77.  
  78.                                 <Setter Property="Background">
  79.                                     <Setter.Value>
  80.                                         <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
  81.                                             <GradientStop Color="#4CECECEC" Offset="0"/>
  82.                                             <GradientStop Color="#FFD4D4D4" Offset="1"/>
  83.                                         </LinearGradientBrush>
  84.                                     </Setter.Value>
  85.                                 </Setter>
  86.  
  87.                                 <Setter Property="Foreground" Value ="#FF7A7A7A"/>
  88.  
  89.                                 <Setter Property="Effect">
  90.                                     <Setter.Value>
  91.                                         <BlurEffect Radius="2" RenderingBias="Quality"/>
  92.                                     </Setter.Value>
  93.                                 </Setter>
  94.  
  95.                             </Trigger>
  96.  
  97.                         </ControlTemplate.Triggers>
  98.  
  99.                     </ControlTemplate>
  100.                 </Setter.Value>
  101.             </Setter>
  102.         </Style>
this gives all the textbox's same theme, i declare it in a Window like this:
Expand|Select|Wrap|Line Numbers
  1. <TextBox Height="23" HorizontalAlignment="Left" Margin="106,175,0,0" Name="textBox1" VerticalAlignment="Top" Width="201" KeyDown="textBox1_KeyDown" />

Now the problem is, i dont see the blinking cursor in textbox, nor can i type/backspace/paste/copy anything in it, i subscribed to the KeyDown event to see if it is detecting key presses, it does but it for some reason not showing the text nor the cursor, also note that if i do not include the " <Setter Property="Template">" and its childs, the textbox works fine, but then it is not completely skinned... any clues?
Feb 6 '10 #1
3 10606
jhardman
3,406 Expert 2GB
The problem is the control template has no instructions for where to put the content, you have told it to draw your textbox as a border ONLY. Unfortunately, I'm not sure what is the best solution, I'm pretty new at WPF myself. I tried this variation (in place of your controltemplate border)
Expand|Select|Wrap|Line Numbers
  1. <Grid>
  2.     <Border BorderThickness="1" 
  3.                 BorderBrush="{TemplateBinding BorderBrush}"
  4.                 Background="{TemplateBinding Background}"/>
  5.     <ContentPresenter HorizontalAlignment="Center"
  6.                                  VerticalAlignment="Center"/>
  7. </Grid>
and this:
Expand|Select|Wrap|Line Numbers
  1. <Border BorderThickness="1" 
  2.         BorderBrush="{TemplateBinding BorderBrush}"
  3.         Background="{TemplateBinding Background}">
  4.     <ContentPresenter HorizontalAlignment="Center"
  5.                                 VerticalAlignment="Center"/>
  6. </Border>
and neither worked, but I'm sure this is the issue (or at least part of the issue).

Jared
Feb 18 '10 #2
jhardman
3,406 Expert 2GB
Found it!
Expand|Select|Wrap|Line Numbers
  1. <Border BorderThickness="1" 
  2.         BorderBrush="{TemplateBinding BorderBrush}"
  3.         Background="{TemplateBinding Background}">
  4.     <ScrollViewer Margin="0" x:Name="PART_ContentHost"/>
  5. </Border>
Let me know if this helps.

Jared
Feb 19 '10 #3
great! works but the text looks... choppy.. like... not anti alised, i dont know.. wierd
Feb 19 '10 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

5
by: Ask | last post by:
Hi, I'm currently having strange problems in Visual Studio .NET. No matter what language I'm writing my programs in, I still can't write the sign "\" - backslash. All I get is a "Y" with two...
3
by: John Hoffman | last post by:
Hello I have a routine that among other things, reads and writes some simple settings to the registry. Everything works fine. I port this program to a windows service and start it and everthing...
5
by: Paul Wilkinson | last post by:
How can I write a method that is called when an object goes out of scope? I've looked all over, so far I've only found discussions of how to write methods that don't = )
7
by: Ritu | last post by:
Hi All, Can any body please tell me how i can write a device driver using CSharp. Thanks, Ritu
3
by: Leo Muller | last post by:
Hi, How can I write text from code behind without getting HTML tags added to it? Up till now I used the label control. But when I call the label.text = "something" then the HTML will output...
4
by: feng | last post by:
..Net's .config file is supposed to replace the .ini files. That's all fine if all I need is to read from it. But what if I need both read and write? With .ini file, I can do that very easily with...
37
by: Spidey | last post by:
How can to write a c program without a main() so i can compile and run it
88
by: Peter Olcott | last post by:
Cab you write code directly in the Common Intermediate language? I need to optimize a critical real-time function.
3
by: ayham | last post by:
I can't Write to XML File using ASP.NET becouse my OS(win xp) tell me that the user(account) that is ASP.net haven't the right to access the file -- ayham...
18
by: Ed Zagmoon | last post by:
I want to write an evil AI in C++ that will be able to evolve and become a dangerous computer-mastermind, something like Skynet. How can I write such an AI in C++ and how can I make it hate...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.