|
Well, if you want to use binding, you can do this:
<StackPanel Orientation="Horizontal">
<TextBlock Text="Hello "/>
<TextBlock Text="{Binding Mode=OneWay, Path=Name}" />
<TextBlock Text=", how are you?" />
</StackPanel>
|
|
|
|
|
I managed to get something like what I wanted, by overriding the user control's OnRender method:
<UserControl ...>
<TextBlock>
Hello <Run x:Name="name" />, how are you?
</TextBlock>
</UserControl>
protected override void OnRender( DrawingContext drawingContext ) {
base.OnRender( drawingContext );
name.Text = Name;
}
Cool.
P.S.
What's that tool everyone uses to copy and paste code into html that fixes angle brackets and all that? I'm getting tired of disabling html in my messages.
|
|
|
|
|
Another really powerful feature of WPF is the ability to use converters. This could be done as:
<local:GreetingConverter x:Key="GreetingFormatter"> This is the actual text.
<StackPanel Orientation="Horizontal">
<TextBlock Text="{Binding Mode=OneWay, Path=Name}"
Converter={StaticResource GreetingFormatter} />
</StackPanel> This would be the class that implements the converter:
using System;
using System.Windows.Data;
namespace MySample.GreetingConverter
{
[ValueConversion(typeof(object),typeof(string))]
public class FormattingConverter: IValueConverter
{
public object Convert(object value, Type targetType,
object parameter, System.Globalization.CultureInfo culture)
{
return string.Format("Hello {0}, how are you?", value);
}
public object ConvertBack(object value, Type targetType,
object parameter, System.Globalization.CultureInfo culture)
{
return null;
}
}
}
|
|
|
|
|
Fascinating. Are converters able to return WPF types, or just primitives? And are they called every time the interface is rendered, or only when things change?
“Time and space can be a bitch.”
–Gushie, Quantum Leap
{o,o}.oO( Looking for a great RSS reader? Try FeedBeast! )
|)””’) Built with home-grown CodeProject components!
-”-”-
|
|
|
|
|
They can convert between any types you want and they're called when the value changes. In 3.5 there is a StringFormat property on the binding itself. You may also want to lookup multi-bindings and multi-input converters.
|
|
|
|
|
Cool, thanks for the tips. I thought you were Pete there for a second, since he's been replying to practically all my questions, so I wanted to thank him; but thank you also.
Logan
“Time and space can be a bitch.”
–Gushie, Quantum Leap
{o,o}.oO( Looking for a great RSS reader? Try FeedBeast! )
|)””’) Built with home-grown CodeProject components!
-”-”-
|
|
|
|
|
No problems mate. I'd disappeared from the boards by the time you asked the followup. Only to glad to help mate.
|
|
|
|
|
I am trying to create labels and textboxes dynamically on a stack panel and I can't display them at run time. The reason I am creating them at run time is I have report names and report parameters stored in a table. When I select a report from a treeview I would like to create the corresponding texboxes and labels based on the data I get from the database. Below is the code for creating Report Parameter fields. In Win forms, I could use
pnlParameter.Control.Add(lbl).
private void CreateRptParmsFields(int ReportNameID)
{
_currCtrl = _staticCtrlCount + 1;
BUI.ReportParameterCollection rpc = BUI.ReportParameterCollection.FetchListByReportNameID(ReportNameID);
foreach (BUI.ReportParameter rp in rpc)
{
Label lbl = CreateLabelControl(rp);
lbl.Tag = rp;
Control ctrl;
switch (rp.Control.ToLower())
{
case "cmb":
ctrl = CreateLabelControl(rp);
break;
default:
ctrl = CreateTextBoxControl(rp);
break;
}
}
}
The two methds below are for creating labels and textboxes respectively.
private TextBox CreateTextBoxControl(BUI.ReportParameter rp)
{
TextBox t = new TextBox();
t.Name = "txt" + rp.Code.Replace("@", "");
return t;
}
private Label CreateLabelControl(BUI.ReportParameter rp)
{
Label lbl = new Label();
lbl.Name = "lbl" + rp.Code.Replace("@", "");
lbl.Width = 150;
lbl.Content = rp.Description;
return lbl;
}
Can anyone show me how to display those fields on a stack panel.
Thanks
|
|
|
|
|
<Window x:Class="HDI_WPF_ListItemTemplate_cs.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300" Loaded="Window_Loaded">
<Grid>
<ListBox x:Name="lstItems" Width="300" MaxHeight="300" FontSize="16">
<ListBox.ItemTemplate>
<DataTemplate>
<Border BorderBrush="Blue" Margin="0,4,0,4" BorderThickness="1" CornerRadius="5">
<StackPanel Orientation="Vertical">
<StackPanel Orientation="Horizontal" Background="AntiqueWhite">
<TextBlock FontSize="16" Text="{Binding Path=FirstName}" />
<TextBlock FontSize="16" Text=" " />
<TextBlock FontSize="16" Text="{Binding Path=LastName}" />
</StackPanel>
<TextBlock FontSize="12" Text="{Binding Path=Age}" />
<TextBlock FontSize="12" Text="{Binding Path=FavoriteMovie}" />
</StackPanel>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
</Grid>
</Window>
public partial class Window1 : Window
{
public Window1()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
lstItems.Items.Add(new MyPeopleData { FirstName = "Han", LastName = "Solo", Age = 45, FavoriteMovie = "Star Wars" });
lstItems.Items.Add(new MyPeopleData { FirstName = "James", LastName = "Kirk", Age = 36, FavoriteMovie = "Star Trek" });
lstItems.Items.Add(new MyPeopleData { FirstName = "Martha", LastName = "Jones", Age = 24, FavoriteMovie = "Dr. Who" });
lstItems.Items.Add(new MyPeopleData { FirstName = "Will", LastName = "Smith", Age = 32, FavoriteMovie = "Independance Day" });
lstItems.Items.Add(new MyPeopleData { FirstName = "Christian", LastName = "Bale", Age = 40, FavoriteMovie = "The Dark Knight" });
lstItems.Items.Add(new MyPeopleData { FirstName = "Hugh", LastName = "Jackman", Age = 46, FavoriteMovie = "Wolverine" });
}
}
public class MyPeopleData
{
public string FirstName { get; set; }
public string LastName { get; set; }
public int Age { get; set; }
public string FavoriteMovie { get; set; }
}
I want to enable context menu for the LSITBOXITEM. CAn any one help me how can i do this...
Santhapur
|
|
|
|
|
Santhapur, try this:
<Window x:Class="HDI_WPF_ListItemTemplate_cs.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300" Loaded="Window_Loaded">
<Window.Resources>
<ContextMenu x:Key="myMenu">
<MenuItem Header="my text" />
</ContextMenu>
</Window.Resources>
<Grid>
<ListBox x:Name="lstItems" Width="300" MaxHeight="300" FontSize="16">
<ListBox.ItemTemplate>
<DataTemplate>
<Border BorderBrush="Blue" Margin="0,4,0,4" BorderThickness="1" CornerRadius="5">
<StackPanel Orientation="Vertical" ContextMenu="{StaticResource myMenu}">
<StackPanel Orientation="Horizontal" Background="AntiqueWhite">
<TextBlock FontSize="16" Text="{Binding Path=FirstName}" />
<TextBlock FontSize="16" Text=" " />
<TextBlock FontSize="16" Text="{Binding Path=LastName}" />
</StackPanel>
<TextBlock FontSize="12" Text="{Binding Path=Age}" />
<TextBlock FontSize="12" Text="{Binding Path=FavoriteMovie}" />
</StackPanel>
</Border>
</DataTemplate>
</ListBox.ItemTemplate>
<ListBox.ItemsPanel>
<ItemsPanelTemplate>
<StackPanel Orientation="Vertical" />
</ItemsPanelTemplate>
</ListBox.ItemsPanel>
</ListBox>
</Grid>
</Window> Here I've added the context menu as a resource, and referred to it from the StackPanel. By doing this, the context menu will only appear when you click on the item itself rather than space at the side.
|
|
|
|
|
How can i parse html files through silverlight?
|
|
|
|
|
|
Hi!
I am working on audio conferencing using WCF and WPF, Visual Studio 2008, C#, Direct Sound. I capture the sound from microphone using DirectSound. Then I send the Audio stream (in byte[]) to the server and broadcast from there. It is working fine and connected clients receive the response from the server. But when the incoming audio stream is played, an unrecognizable sound is coming.
I simultaneously run two thread for sending data to the server.
Constructor --
public AudioConferencing()
{
Initialize();
senderThread = new Thread(new ThreadStart(Send));
receiverThread = new Thread(new ThreadStart(PlayAudioStream));
}
private void Send()
{
try
{
captureBuffer = new CaptureBuffer(captureBufferDescription, capture);
CreateNotifyPositions();
captureBuffer.Start(true);
bool readFirstBufferPart = true;
int offset = 0;
MemoryStream memStream = new MemoryStream(halfBuffer);
bStop = false;
while (!bStop)
{
if (bIsSendingActive)
{
autoResetEvent.WaitOne();
captureBuffer.Read(offset, memStream, halfBuffer, LockFlag.None);
byte[] dataToWrite = memStream.GetBuffer();
SendAudioEvent(dataToWrite);
}
}
}
catch (Exception ex)
{
MessageBox.Show(ex.Message, "VoiceChat-Send ()", MessageBoxButtons.OK);
}
finally
{
captureBuffer.Stop();
}
}
public void StartPlaying(byte[] AudioStream)
{
playbackBuffer.Write(?, byteDecodedData, LockFlag.None);
playbackBuffer.Play(?, BufferPlayFlags.Default);
}
BINDING DETAILS --
----------------------------------------------------------------------------------------------------------------------------------------
binding="netTcpBinding"
bindingConfiguration="DuplexBinding"
<nettcpbinding>
<binding name="DuplexBinding" receivetimeout="00:00:20" sendtimeout="00:00:10">
maxBufferPoolSize="67108864" maxBufferSize="67108864" maxConnections="100"
maxReceivedMessageSize="67108864" portSharingEnabled="true">
<readerquotas maxstringcontentlength="67108864" maxarraylength="67108864">
maxBytesPerRead="67108864" />
<reliablesession enabled="true" />
<security mode="None" />
</readerquotas></binding>
</nettcpbinding>
---------------------------------------------------------------------------------------------------------------------------------------
I want to know how to write the DirectSound playback Buffer - by the audio stream coming from the server and how to track the rate of playing position and write position.
Please give me the complete guideline (any reference website/code).
Thank you.
Sumanta Chatterjee
Web - www.chatterjeesoft.qsh.in
|
|
|
|
|
I want to know how can we parse multiple XML files present in a URL
in silverlight. I want some code help in c#
modified on Thursday, September 4, 2008 4:49 AM
|
|
|
|
|
skrajasthan wrote: I want to know how can we parse multiple XML files present in a URL
in silverlight. I want some code help in c#
I'm sorry, but you seem to be under the misapprehension that we do your work for you. That's not what these forums are for - they are for you to tell us what you've tried, and then for us to give you some pointers to help out. That's it.
|
|
|
|
|
How can I read more than one xml files with different names through silverlight?
|
|
|
|
|
|
Can any one give me idea how i can validate a texbox. I mean user should enter some thing in the textbox(Like Required field validation in asp.net). Please give me a simple example.
|
|
|
|
|
Well - there are many ways to perform validation in WPF. Here's an example of a validation rule that ensures that your input matches a particular format. The first part is a C# class:
public MatchRule : ValidationRule
{
public string MatchText { get; set; }
public override ValidationResult Validate(object value,
CultureInfo info)
{
if ((string)value == MatchText)
return new ValidationResult(true, null);
return new ValidationResult(false, "This is not a match");
}
} and in the XAML:
<TextBox>
<TextBox.Text>
<Binding.ValidationRules>
<local:MatchRule MatchText="Hello" />
</Binding.ValidationRules>
</TextBox.Text>
</TextBox>
|
|
|
|
|
Hi
i have a simple expander control with a button, here is my xaml code :
<Grid>
<Expander Name="expander1" Margin="10" IsExpanded="True" Background="Silver"
Collapsed="expander1_Collapsed" Expanded="expander1_Expanded">
<Expander.Header>
<Image Source="E:\Tutorial\FullComponent\Ajax Loader\ajax-loader2.gif"></Image>
</Expander.Header>
<Expander.Content>
<Button Margin="20" Height="30" Name="button1" Click="button1_Click">Click Me</Button>
</Expander.Content>
</Expander>
</Grid>
my problem is that how to animate expander control (callopsing/expanding)?
thanks
|
|
|
|
|
This[^] might help. It helped me when I did the same.
|
|
|
|
|
How can we parse or read a complete .eml file in silverlight and display the information and c# .
Please provide me the solution code for it.
Thanks
|
|
|
|
|
HI
Can any ley me know, what are the adavantages of Silver light for the user who is using silver light application, kindly reply ASAP, thankx in advance.
|
|
|
|
|
I ‘m working on audio conferencing in - WCF, WPF and Visual Studio 2008 using C#. I capture the sound from microphone using Windows API. Then I continuously capture the sound from microphone and send the Audio stream (byte[]) to the server and broadcast from there. Its working fine and I also get the response from the server as well. Then I play the Audio Stream(byte[]) coming from the server.
I used this article in codeproject website to record and play audio stream.
http://www.codeproject.com/KB/audio-video/cswavrec.aspx
But when the incoming audio stream is playing, an unrecognizable sound is coming. This may be due to the difference between data consuming and receiving rates.
I also used directsound to record and playing sound but the same problem arise.
So please suggest me how to solve this problem( Better DierctSound suggestion – Streaming Buffer) .
This code is fire when audio stream is received from the server.
private void playAudio()
{
objAudioConferencingPlayer.StartAudioPlayer(IncommingAudioStream);
}
public void StartAudioPlayer(byte[] AudioStream)
{
if (!IsPlayerRunning)
{
StopPlaying();
m_Player = new WaveOutPlayer(-1, fmt, 16384, 3, new
BufferFillEventHandler(Filler));
IsPlayerRunning = true;
}
m_Fifo.Write(AudioStream, 0, AudioStream.Length);
}
private void Filler(IntPtr data, int size)
{
if (m_PlayBuffer == null || m_PlayBuffer.Length < size)
m_PlayBuffer = new byte[size];
if (m_Fifo.Length >= size)
m_Fifo.Read(m_PlayBuffer, 0, size);
else
for (int i = 0; i < m_PlayBuffer.Length; i++)
m_PlayBuffer[i] = 0;
System.Runtime.InteropServices.Marshal.Copy(m_PlayBuffer, 0, data, size);
}
Thanks in Advance.
|
|
|
|
|
Hi
I have a simple question regarding following code.
How do I save whatever shown within the border tags into a image file such as tiff?
<Window x:Class="Canvas.Window1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="Window1" Height="300" Width="300">
<Border x:Name="myborder" BorderBrush="Black" BorderThickness="1" Width="2.1in" Height="2.02in">
<Canvas Width="2.1in" Height="2.02in">
<Rectangle Width="1.625in" Height="1.625in" Stroke="Black" StrokeThickness="0.6pt" Canvas.Left="33" Canvas.Top="18" />
</Canvas>;
</Border>;
</Window>;
|
|
|
|