I'm developing a Silverlight application where I want to simulate a console. There are a lot of ways to represent this - StackPannels, grid of TextBoxes, etc - and I was wondering what the bets fit would be?
Requirements:
Display an 80x20 grid that scales based on parent size
Be able to update an individual cell's character
Be able to set a cell's forground and background color
Why would you use TextBox instead of TextBlock.
I think you should use 1 TextBlock and format the text like:
<TextBlock>
<Run FontWeight="Bold">Hello There.</Run>
<Run Foreground="Red">How are you?</Run>
<Run FontStyle="Italic">I am fine thanks!</Run>
<Run>漢字</Run>
</TextBlock>
And start with setting 80*20 space keys.
Then implement some algoritmen to find a specific character and fx to set its Foreground by clipping it out of the Run it is in and make some new Run objects.
And wire up some events to receive new keys. Or use one TextBlock where the keyboard pointer is.
You could also get inspiration from here:
http://silverlight.net/content/samples/sl2/dlrconsole/index.html
- you can download the code to the DLRConsole
Grid filled with Textboxes?
But wait... 1600 Text boxes... I don't know what to do, sorry ((
Related
I'm creating a chat in WPF and I'm trying to make user can send emoji. The user writes a message in a TextBox and he can open menu with emoji and choose some. A probem is that emoji are not colored, but they are black and white.
I tried to use emoji.wpf, but it works only in RichTextBox (I need buttons and TextBox too) and the emoji are rendering very slowly. Somewere I read that the only solution is to insert emoji as pictures. Is it true or it exists some better solution? It would be advisable to have emoji as unicode characters, not pictures.
Sorry for my english, I'm from Czech Republic.
I wrote Emoji.Wpf; here are a few comments:
There is an Image class that can be trivially used in a Button. See for instance the font viewer sample which uses simple XAML like this: <emoji:Image Width="44" Height="44" Text="{Binding UnicodeText}"/>
It is quite difficult to subclass TextBox for colour emoji because it only supports a single font and font style; overriding the rendering code seems difficult and I am not skilled enough to do it.
Here is what the font viewer looks like:
I found a very easy and great method!
Just add a Nuget package named "Emoji.Wpf" and use it as below:
<Window ...
xmlns:emoji="clr-namespace:Emoji.Wpf;assembly=Emoji.Wpf"
...>
...
<emoji:TextBlock FontSize="24" Text="💖😁🐨🐱🐉👩🏿👩🏻👦🏽"/>
...
</Window>
And it works well for my WPF app.
More information in it's project site:
https://github.com/samhocevar/emoji.wpf
I want to create a WPF a similar to the one in the image so that i can Bind the Image Source, The Movie Name & The Category (Ignore the left side)
Is this a ListView ? I tried many different combos but i couldn't make it as the one above.
Also, since it is related to that question, how i can have dynamically column number based on the Window size? For example in the image above the columns are 5, but i want it to be dynamically based on the Window Pixel/Size. Is this possible?
A lot of work to learn how to do it in a ListView. I'm not sure if the widths can be dynamic (based on each image width) but I've done it similarly to how Windows Explorer Icons views does it. So extra large, large, etc.
A good starting point for this is at https://msdn.microsoft.com/en-us/library/ms748859
But it's a tonne of work. Probably 2 or 3 months. They only give you bits and pieces and it's a variety of C# and VB.
You might want a more low-level ItemsControl.
Try the example from here: http://www.wpf-tutorial.com/list-controls/itemscontrol/
The one that might work for you is the WrapPanel as it will change the wrapping / layout based on the available container size and the item size.
Your Image and Text controls with bindings would go in the DataTemplate.
I'm having a little problem, i have Custom list box item, that is 165 px height. So, the text block wraps text and gets 50% height of the list box item, example:
How you noticed the text size is too big.
Is there a way to make fint size exatly big to fit in the textblock?
As far as my understanding it can be done with help of textBox.Text.Length property. Also It depends on the font you are using.
What happens when the Text is 10000 characters long? Rather than trying to show all of the text you should make the font smaller (no need for something that large) and use TextTrimming. TextTrimming will cut the text short and put an ellipse at the end.
<TextBlock Text="{Binding MyProperty}" TextTrimming="WordEllipsis" />
i have "search TextBox" to search in treeview, i give result very well. But i want to get those parts get Bold which i typed in "search TextBox" of my winform.
Ex: i Typed Ram then it gives *Ram*esh .
The TreeNode class doesn't support that, its Text is always drawn with one font, the TreeView.Font. Making parts of the text bold is technically possible but very hard to get right. You need to enable custom drawing with the TreeView.DrawMode property and DrawItem event, there's a good example of it in the MSDN Library article.
That's the easy part, the hard problem is that the node is too small to fit the text after you draw parts of it in a bold font. TreeView is missing a "MeasureNodeText" event that would allow you to ask for enough space. The only workaround for that is to lie about the node text and make it artificially wider by prefixing characters. Which you then don't draw in the DrawItem event. Very hard to get consistently right, you'll want to consider a fixed pitch font instead.
I cannot recommend you pursue this unless the feature is really important to you. This otherwise explains why you never see this feature in other programs. Consider changing the color instead of the font weight too. Still hard to glue the pieces together btw.
I have seen many other samples out there that draw smooth text on glass. But I can't use them. I need every single label that gets added at runtime to be smooth. I can't just "draw" text onto the screen.
Is this at all possible, and are there and sources around?
Thank you
Take a long at this article http://msdn.microsoft.com/en-us/magazine/cc163435.aspx#S6
It's a bit long but it answers alot of your question and alore more in regards to glass.
but the relevant part for you directly is
One particular gotcha is that
rendering a GDI item in black uses the
bit pattern 0x00000000-which also
happens to be a completely transparent
black if you are using an alpha
channel. This means that if you draw
with a black GDI brush or pen you'll
get a transparent color, not a black
one. The biggest problem this presents
is when you try to use the default
text color in a control of a text
label that sits on the glass area.
Since the default text color is
usually black, the DWM will consider
this to be transparent and the text
will be written in the glass
incorrectly. An example can be seen in
Figure 10. The first line is written
with GDI+, the second is a text label
control using the default color. As
you can see, it's nearly illegible
because it's actually incorrectly
rendered text that shows up as gray,
not black.
Happily, there are a number of ways
around this problem. Using owner-draw
controls is one. Rendering to a bitmap
that has an alpha channel is another.
Fortunately, the easiest way to get
text on controls is to let the .NET
Framework 2.0 use GDI+ for you. This
is easily accomplished by setting the
UseCompatibleTextRendering property on
your controls. By default, this
property is set to false so that
controls written for previous versions
of the .NET Framework will render the
same. But if you set it to true, your
text will come out looking correct.
You can set the property globally with
the
Application.SetUseCompatibleTextRenderingDefault
method.
He also provides example code you can place in your Main()
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(true);
Application.Run(new GlassForm());
}
But I recommend reading the article, It'll clear up alot of what's going on with Aero/Glass
Cheers,
Phyx