Databinding in wpf as that of repeater in asp.net - wpf

I am having a repeater like this in asp.net
<asp:Repeater runat="server" ID="rptrExperience" OnItemDataBound = "itembound">
<ItemTemplate>
<div class="experience">
<a><asp:Label ID="Label13" class="accounts-link" runat="server" Text='<%#Eval("JobTitle") %>'></asp:Label></a> <br />
<a> <asp:Label ID="Label14" class="accounts-link" runat="server" Text='<%#Eval("Company") %>'></asp:Label></a><br />
<%-- <asp:Label ID="Label1" runat="server" Text='<%#Eval("town") %>'></asp:Label><br />
<asp:Label ID="Label15" runat="server" Text='<%#Eval("Location") %>'></asp:Label><br />--%>
<asp:Label ID="Label16" runat="server" Text='<%#Eval("Period") %>'></asp:Label><br />
<asp:Label ID="Label17" runat="server" Text='<%#Eval("Description") %>'></asp:Label><br />
<asp:Label ID="lblname" runat="server"></asp:Label>
<a id="ae" href="#?w=750" class=" floatleft poplight" rel="popup6" runat ="server" >Endorse <asp:Label ID="en" runat="server" Text='<%#Name(Eval("UserId")) %>'></asp:Label>'s Work in <asp:Label ID="en1" runat="server" Text='<%#Eval("Company") %>'></asp:Label></a>
<a id="te" runat="server" rel="tooltip" title="You can endorse your collegue or friend you have worked together.This is your professional opinion so keep it professional.Tip: Keep it clear and simple, Your friend can delete your endorsementif they are innappropriate. "><img src="images/icon-tips.png" width="14" height="15" alt="tips" /></a>
</div>
</ItemTemplate>
</asp:Repeater>
and binding data using linq
I want the same to displayed in a wpf application. I am new to wpf can any one help me out

I think ItemsControl will probably fit your need:
<ItemsControl ItemsSource="{Binding ...}">
<ItemsControl.ItemTemplate>
<DataTemplate>
<!-- Template goes here ... -->
</DataTemplate>
</ItemsControl.ItemTemplate>
</ItemsControl>

Related

WPF WindowsFormsHost control is not woking showing error

I am using WindowsFormsHost to show DataGridView in my WPF application.
<wfi:WindowsFormsHost Name="winhost" Grid.Row="0" Width="930" Height="200" Margin="5,5,5,0" Visibility="Hidden">
<wf:DataGridView x:Name="dataGridViewOutlookMailList" ScrollBars="Both" AllowUserToAddRows="False" RowHeadersVisible="False" CellContentClick="dataGridViewOutlookMailList_CellContentClick">
<wf:DataGridView.Columns>
<wf:DataGridViewCheckBoxColumn Name="dataGridViewCheckBoxColumn3" HeaderText="" Width="25" Visible="True" />
<wf:DataGridViewTextBoxColumn Name="dataGridViewTextBoxColumn13" HeaderText="Outlook Entry ID" Width="100" Visible="false" />
<wf:DataGridViewTextBoxColumn Name="dataGridViewTextBoxColumn14" HeaderText="FullPath With FileName" Width="100" Visible="False" />
<wf:DataGridViewTextBoxColumn Name="dataGridViewTextBoxColumn15" HeaderText="Resume Name" Width="100" Visible="True" />
<wf:DataGridViewTextBoxColumn Name="dataGridViewTextBoxColumn18" HeaderText="Sender Name" Width="100" Visible="True" />
<wf:DataGridViewTextBoxColumn Name="dataGridViewTextBoxColumn17" HeaderText="Received By Name" Width="100" Visible="True" />
<wf:DataGridViewTextBoxColumn Name="dataGridViewTextBoxColumn16" HeaderText="Received" Width="100" Visible="True" />
<wf:DataGridViewTextBoxColumn Name="dataGridViewTextBoxColumn19" HeaderText="Sender Address" Width="100" Visible="True" />
<wf:DataGridViewTextBoxColumn Name="dataGridViewTextBoxColumn20" HeaderText="To" Width="100" Visible="True" />
<wf:DataGridViewTextBoxColumn Name="dataGridViewTextBoxColumn21" HeaderText="Bcc" Width="100" Visible="True" />
<wf:DataGridViewTextBoxColumn Name="dataGridViewTextBoxColumn22" HeaderText="Cc" Width="100" Visible="True" />
<wf:DataGridViewTextBoxColumn Name="dataGridViewTextBoxColumn23" HeaderText="Subject" Width="100" Visible="True" />
<wf:DataGridViewTextBoxColumn Name="dataGridViewTextBoxColumn24" HeaderText="Body" Width="100" Visible="True" />
<wf:DataGridViewCheckBoxColumn Name="dataGridViewCheckBoxColumn4" HeaderText="NotesActivity" Width="25" Visible="False" />
<wf:DataGridViewCheckBoxColumn Name="dataGridViewCheckBoxColumn5" HeaderText="Body As Attachment" Width="100" Visible="False" />
</wf:DataGridView.Columns>
</wf:DataGridView>
I am getting following error while mouse over on datagridview also the UI is not loaded properly. see the screen shot for details.
I am also using following code
WinForms.DataGridViewCellStyle ColStyle1 = new WinForms.DataGridViewCellStyle();
System.Drawing.Text.PrivateFontCollection pfc = new System.Drawing.Text.PrivateFontCollection();
pfc.AddFontFile(Environment.GetFolderPath(Environment.SpecialFolder.CommonApplicationData) + #"\NewZrr\OpenSans-Regular.ttf");
foreach (WinForms.DataGridViewColumn c in dataGridViewOutlookMailList.Columns)
{
c.DefaultCellStyle.Font = new System.Drawing.Font(pfc.Families[0], 8, System.Drawing.FontStyle.Regular);
}
pfc = null;
in my Window_Loaded method to change the font of datagridview. kindly guide me to resolve the issue.
The problem is that the PrivateFontCollection instance in the pfc variable goes out of scope, so when the DataGridViewCell is drawn for the first time the specified font cannot be loaded correctly.
Move the pfc instance outside the Window_Loaded method to prevent GC from collecting it, and do not set it to null, make it a long-living object.
Reference: Parameter is not valid when draw text in label with custom font

Check checkbox when another checkbox is checked

Here is my WIX:
<Control Id="FeatureOneBox" Type="CheckBox" Property="FEATUREONE" Text="Feature One" X="30" Y="87" Height="10" Width="200" CheckBoxValue="1" />
<Control Id="FeatureTwoBox" Type="CheckBox" Property="FEATURETWO" Text="Feature Two" X="30" Y="107" Height="10" Width="200" CheckBoxValue="1" />
<Control Id="FeatureThreeBox" Type="CheckBox" Property="FEATURETHREE" Text="Feature Three" X="30" Y="107" Height="10" Width="200" CheckBoxValue="1" />
<Control Id="CoreFeatureBox" Type="CheckBox" Property="INSTALLCORE" Text="!(loc.CoreFeatureBox)" X="30" Y="147" Height="10" Width="300" CheckBoxValue="1">
<Condition Action="enable"><![CDATA[FEATURETWO <> 1 AND FEATURETHREE <> 1]]></Condition>
<Condition Action="disable">FEATURETWO = 1 OR FEATURETHREE = 1</Condition>
</Control>
I want to require the Core feature if either feature two or three is selected. I can do this by altering the feature condition but, it the user unchecks both of those, unchecks Core, then rechecks one of those, I don't want to install the Core feature even though its checkbox is unchecked.
How can I check CoreFeatureBox at the same time I disable it?
If only I'd googled just a few minutes more!
This code is all I needed:
<Control
Id="CB1"
Type="CheckBox"
Property="myCheckboxResult"
CheckBoxValue="my value"
Text="Check the box please."
X="50"
Y="50"
Height="10"
Width="150">
<Publish Property="myCheckboxResult2" Value="my value" Order="1">myCheckboxResult</Publish>
<Publish Property="myCheckboxResult2" Value="{}" Order="2">NOT myCheckboxResult</Publish>
</Control>
<Control
Property="myCheckboxResult2"
Id="CB2"
Type="CheckBox"
CheckBoxValue="my value"
Text="Check the box please."
X="50"
Y="70"
Height="10"
Width="150" />
I added the <Publish/> nodes under FeatureTwoBox and FeatureThreeBox and everything's working.

WPF FlowDocument to XPS rendering with text rotation effect

I am rendering XPS using WPF. This is completely dynamic (XAML free).
In my code, I have following code to set up text rotation.
Private Shared Sub ApplyRotation(style As BoxStyleData, run As TextElement)
If style IsNot Nothing Then
If Math.Abs(style.TextRotation) > Double.Epsilon Then
Dim effects = New TextEffectCollection
Dim effect = New TextEffect()
effect.Transform = New RotateTransform(style.TextRotation)
effect.PositionCount = 100
effects.Add(effect)
run.TextEffects = effects
End If
End If
End Sub
It is inside FlowPanel, therefore some bug is preventing me from setting rotation for whole paragraph (more on that here http://social.msdn.microsoft.com/Forums/nl/wpf/thread/931f1995-d039-4364-b09b-fcd0a43fd737)
My problem is, even when I use the fix, result is not correct. After certain amount of characters, text is not rotated anymore:
Note, that screenshot is from XPS to which I render result.
When I render it to XAML, you can see that effect is correctly mapped to all Runs in text.
<Paragraph Margin="0,0,0,0" Padding="0,18.9,0,0" TextAlignment="Center" ClearFloaters="None" FontSize="14.62">
<Span FontSize="14.62"><Run><Run.TextEffects><TextEffect PositionCount="100"><TextEffect.Transform><RotateTransform Angle="356.7" /></TextEffect.Transform></TextEffect></Run.TextEffects>Denken Sie frühzeitig</Run></Span><LineBreak />
<Span FontSize="14.62"><Run><Run.TextEffects><TextEffect PositionCount="100"><TextEffect.Transform><RotateTransform Angle="356.7" /></TextEffect.Transform></TextEffect></Run.TextEffects>an den</Run></Span><LineBreak />
<Span FontSize="14.62"><Run><Run.TextEffects><TextEffect PositionCount="100"><TextEffect.Transform><RotateTransform Angle="356.7" /></TextEffect.Transform></TextEffect></Run.TextEffects>Räderwechsel!</Run></Span><LineBreak />
<LineBreak />
<Span FontSize="14.62"><Run><Run.TextEffects><TextEffect PositionCount="100"><TextEffect.Transform><RotateTransform Angle="356.7" /></TextEffect.Transform></TextEffect></Run.TextEffects>Unser</Run></Span><LineBreak />
<Span FontWeight="Bold" FontSize="14.62"><Run><Run.TextEffects><TextEffect PositionCount="100"><TextEffect.Transform><RotateTransform Angle="356.7" /></TextEffect.Transform></TextEffect></Run.TextEffects>Winter Check-Point</Run></Span><LineBreak />
<Span FontSize="14.62"><Run><Run.TextEffects><TextEffect PositionCount="100"><TextEffect.Transform><RotateTransform Angle="356.7" /></TextEffect.Transform></TextEffect></Run.TextEffects>ist für Sie offen!</Run></Span></Paragraph>
Now, does anyone has any idea how to achieve rotation for whole text as I really need it.
Thanks
EDIT:
For quick test that it does not work properly, you can create WPF application and just paste following XAML Code
<Window x:Class="MainWindow"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
Title="MainWindow" Height="350" Width="525">
<Grid>
<FlowDocumentPageViewer>
<FlowDocument>
<Paragraph Margin="0,0,0,0" Padding="0,18.9,0,0" TextAlignment="Center" ClearFloaters="None" FontSize="14.62">
<Span FontSize="14.62">
<Run>
<Run.TextEffects>
<TextEffect PositionCount="100">
<TextEffect.Transform>
<RotateTransform Angle="356.7" />
</TextEffect.Transform>
</TextEffect>
</Run.TextEffects> Denken Sie frühzeiti
</Run>
</Span>
<LineBreak />
<Span FontSize="14.62">
<Run>
<Run.TextEffects>
<TextEffect PositionCount="100">
<TextEffect.Transform>
<RotateTransform Angle="356.7" />
</TextEffect.Transform>
</TextEffect>
</Run.TextEffects> an den
</Run>
</Span>
<LineBreak />
<Span FontSize="14.62">
<Run>
<Run.TextEffects>
<TextEffect PositionCount="100">
<TextEffect.Transform>
<RotateTransform Angle="356.7" />
</TextEffect.Transform>
</TextEffect>
</Run.TextEffects> Räderwechsel!
</Run>
</Span>
<LineBreak />
<LineBreak />
<Span FontSize="14.62">
<Run>
<Run.TextEffects>
<TextEffect PositionCount="100">
<TextEffect.Transform>
<RotateTransform Angle="356.7" />
</TextEffect.Transform>
</TextEffect>
</Run.TextEffects> Unser
</Run>
</Span>
<LineBreak />
<Span FontWeight="Bold" FontSize="14.62">
<Run>
<Run.TextEffects>
<TextEffect PositionCount="100">
<TextEffect.Transform>
<RotateTransform Angle="356.7" />
</TextEffect.Transform>
</TextEffect>
</Run.TextEffects> Winter Check-Point
</Run>
</Span>
<LineBreak />
<Span FontSize="14.62">
<Run>
<Run.TextEffects>
<TextEffect PositionCount="100">
<TextEffect.Transform>
<RotateTransform Angle="356.7" />
</TextEffect.Transform>
</TextEffect>
</Run.TextEffects> ist für Sie offen!
</Run>
</Span>
</Paragraph>
</FlowDocument>
</FlowDocumentPageViewer>
</Grid>
</Window>
So, I've fixed it by switching
effect.PositionCount = 100
to
effect.PositionCount = Integer.Max
which fixed the problem.
I did not understand correctly what it stood for and thought it means something like percentage of effect done.

ext.net filter on grid

have my store and my grid panel, i need to add a filter box to it , so added a topbar tag, that has the field box to filter.. and want to add listeners on it so i would be filterer while writing, the 2 functions as shown are filtergrid() and clearFilter()...what those 2 functions should be, knowing that the store is binded with code behind...
<ext:Store ID="Store1" runat="server">
<Reader>
<ext:JsonReader>
<Fields>
<ext:RecordField Name="FULLNAME" />
<ext:RecordField Name="JOBTITLE" />
<ext:RecordField Name="PHONENUMBER1" />
</Fields>
</ext:JsonReader>
</Reader>
</ext:Store>
<ext:Panel ID="Panel1" runat="server" Width="520" Height="300" Collapsible="true" Title="Add Attendies" Collapsed="true">
<TopBar>
<ext:Toolbar ID="Toolbar2" runat="server">
<Items>
<ext:ToolbarTextItem ID="ToolbarTextItem1" runat="server" Text="Filter:" />
<ext:ToolbarSpacer />
<ext:TriggerField ID="TriggerField1" runat="server" EnableKeyEvents="true">
<Triggers>
<ext:FieldTrigger Icon="Clear" />
</Triggers>
<Listeners>
**<KeyUp Fn="filtergrid()" Buffer="250" />
<TriggerClick Handler="clearFilter();" />**
</Listeners>
</ext:TriggerField>
</Items>
</ext:Toolbar>
</TopBar>
<Items>
<ext:BorderLayout ID="BorderLayout1" runat="server">
<West MarginsSummary="5 5 5 5">
<ext:GridPanel
ID="GridPanel1"
runat="server"
StoreID="Store1"
DDGroup="GridDDGroup"
EnableDragDrop="true"
StripeRows="true"
AutoExpandColumn="FULLNAME"
Width="250"
Title="All Contacts">
<ColumnModel>
<Columns>
<ext:Column Header="Contact Name" ColumnID="FULLNAME" Width="140" DataIndex="FULLNAME" />
<ext:Column Header="Title" ColumnID="JOBTITLE" Width="75" DataIndex="JOBTITLE" />
<ext:Column Header="Phone" ColumnID="PHONENUMBER1" Width="75" DataIndex="PHONENUMBER1" />
</Columns>
</ColumnModel>
<SelectionModel>
<ext:RowSelectionModel ID="RowSelectionModel1" runat="server" />
</SelectionModel>
<GetDragDropText Fn="getDragDropText" />
<Listeners>
<Render Fn="setDD" />
</Listeners>
</ext:GridPanel>
</West>
<Center MarginsSummary="5 5 5 0">
<ext:GridPanel
ID="GridPanel2"
runat="server"
StoreID="Store2"
DDGroup="GridDDGroup"
EnableDragDrop="true"
StripeRows="true"
AutoExpandColumn="FULLNAME"
Width="250"
Title="Meeting Attendies">
<ColumnModel>
<Columns>
<ext:Column ColumnID="Contact Name" Header="Contact Name" Width="140" DataIndex="FULLNAME" />
<ext:Column Header="Title" Width="75" DataIndex="JOBTITLE" />
<ext:Column Header="Phone Number" Width="75" DataIndex="PHONENUMBER1" />
</Columns>
</ColumnModel>
<SelectionModel>
<ext:RowSelectionModel ID="RowSelectionModel2" runat="server" />
</SelectionModel>
<GetDragDropText Fn="getDragDropText" />
<Listeners>
<Render Fn="setDD" />
</Listeners>
</ext:GridPanel>
</Center>
</ext:BorderLayout>
</Items>
<BottomBar>
<ext:Toolbar ID="Toolbar1" runat="server">
<Items>
<ext:ToolbarFill ID="ToolbarFill1" runat="server" />
<ext:Button ID="Button1" runat="server" Text="Reset both grids">
<Listeners>
<Click Handler="Store1.loadData(Store1.proxy.data);Store2.removeAll();" />
</Listeners>
</ext:Button>
</Items>
</ext:Toolbar>
</BottomBar>
</ext:Panel>
so there is 2 functions that i have to write , one that filter an return the result to be written in the panel, and the other one is to clear and restore the datasource again.
You can apply a filter using the filterBy method and passing a delegate function which returns true or false based on some logic of your choosing and then remove the filter using clearFilter
In mode cody terms, something like this:
clearFilter() {
theGridPanel.store.clearFilter(false);
}
filterGrid() {
theGridPanel.store.filterBy(theFilterFunction)
}
theFilterFunction(record, id) {
if(record.data.aField === 'yellow') {
return true;
}
return false;
}

WPF FlowDocument Symmetric Layout

How can a symmetric layout be generated using one FlowDocument?
My code is:
<Grid Name="grid1">
<FlowDocumentScrollViewer Name="name1" Margin="6,0,17,0">
<FlowDocument>
<Paragraph>
<Figure HorizontalAnchor="PageLeft" VerticalAnchor="PageTop" Width="0.5content">
<BlockUIContainer>
<Button >HelloTwo</Button>
</BlockUIContainer>
</Figure>
<Figure HorizontalAnchor="PageRight" VerticalAnchor="PageTop" Width="0.5content">
<BlockUIContainer>
<Button >HelloTwo</Button>
</BlockUIContainer>
</Figure>
</Paragraph>
</FlowDocument>
</FlowDocumentScrollViewer>
</Grid>
I want them to be aligned side-by-side with each one's content in the same position.
How can I achieve this layout?
You should use FlowDocumentReader or FlowDocumentPageViewer. Using FlowDocumentScrollViewer, Figure is treated as different anchored block, and can't be paired side by side.

Resources