Sometimes, you want a Mouse Over event to trigger a style change on some or all the items within a container.
Changing Image style when a Mouse moves over a custom parent container (WC_MenuItem). Any type of container or Panel can be substituted for the custom type I've used.
<Image x:Name="imgHelpLink" Source="pack://application:,,,/Weblink_WPF;component/Images/Help.png" Cursor="Hand" Grid.Column="1" Width="16" Height="16" Margin="0,0,0,0" ToolTip="Click to view the Knowledgebase article on this report" HorizontalAlignment="Right" >
<Image.Style>
<Style TargetType="{x:Type Image}">
<Setter Property="Opacity" Value="0" />
<Style.Triggers>
<DataTrigger Binding="{Binding RelativeSource={RelativeSource Mode=FindAncestor,AncestorType={x:Type weblink_controls:WC_MenuItem}},Path=IsMouseOver}" Value="True">
<Setter Property="Opacity" Value="1" />
</DataTrigger>
<!--<DataTrigger Binding="{Binding Path=HelpLink.Length}" Value="0">
<Setter Property="Opacity" Value="0.3"/>
</DataTrigger>-->
</Style.Triggers>
</Style>
</Image.Style>
</Image>
Saturday, January 28, 2012
Serializing and DeSerializing Objects as XML in VB.NET
It was unbelievably difficult to find a working example where the XML could come from a web server on a different domain. So, I guess I will share with the world how I managed to make it work.
Serialize List of Objects to XML (Web Server)
Dim xml As String = ""
Dim mstr_XmlFilePath As String = "/myFolder/myFile.xml"
Dim mstr_ServerXmlFilePath As String = Server.mapPath(mstr_XmlFilePath)
Dim obj_objMyObject As New objMyObject
Dim lst_objMyObject As List(Of objMyObject) = [[***populate object***]]
Try
Dim ser As XmlSerializer
ser = New XmlSerializer(GetType(System.Collections.Generic.List(Of objMyObject)))
Dim memStream As New MemoryStream
Dim xmlWriter As New XmlTextWriter(memStream, Encoding.UTF8)
xmlWriter.Namespaces = True
ser.Serialize(xmlWriter, lst_objMyObject)
xmlWriter.Close()
memStream.Close()
xml = Encoding.UTF8.GetString(memStream.GetBuffer())
xml = xml.Substring(xml.IndexOf(Convert.ToChar(60)))
xml = xml.Substring(0, (xml.LastIndexOf(Convert.ToChar(62)) + 1))
My.Computer.FileSystem.WriteAllText(XmlFilePath, xml, False)
Catch ex As Exception
Throw New Exception("Error calling ToXML. " & ex.GetBaseException.ToString)
End Try
DeSerialize List of Objects from XML (Client or Cross-Domain Web Server)
str_XmlFullFilePath = "myURL" + mstr_XmlFilePath
Dim objListFromXml As New List(Of objMyObject)
Try
Dim reader As System.Xml.XmlReader
reader = System.Xml.XmlReader.Create(str_XmlFullFilePath)
Dim mySerializer As XmlSerializer = New XmlSerializer(GetType(System.Collections.Generic.List(Of objMyObject)))
objListFromXml = CType(mySerializer.Deserialize(reader), System.Collections.Generic.List(Of objMyObject))
Catch
'don't do anything. If error occurs, return an empty object
End Try
I may have some typos above. I replaced all my variables with more generic ones.
Serialize List of Objects to XML (Web Server)
Dim xml As String = ""
Dim mstr_XmlFilePath As String = "/myFolder/myFile.xml"
Dim mstr_ServerXmlFilePath As String = Server.mapPath(mstr_XmlFilePath)
Dim obj_objMyObject As New objMyObject
Dim lst_objMyObject As List(Of objMyObject) = [[***populate object***]]
Try
Dim ser As XmlSerializer
ser = New XmlSerializer(GetType(System.Collections.Generic.List(Of objMyObject)))
Dim memStream As New MemoryStream
Dim xmlWriter As New XmlTextWriter(memStream, Encoding.UTF8)
xmlWriter.Namespaces = True
ser.Serialize(xmlWriter, lst_objMyObject)
xmlWriter.Close()
memStream.Close()
xml = Encoding.UTF8.GetString(memStream.GetBuffer())
xml = xml.Substring(xml.IndexOf(Convert.ToChar(60)))
xml = xml.Substring(0, (xml.LastIndexOf(Convert.ToChar(62)) + 1))
My.Computer.FileSystem.WriteAllText(XmlFilePath, xml, False)
Catch ex As Exception
Throw New Exception("Error calling ToXML. " & ex.GetBaseException.ToString)
End Try
DeSerialize List of Objects from XML (Client or Cross-Domain Web Server)
str_XmlFullFilePath = "myURL" + mstr_XmlFilePath
Dim objListFromXml As New List(Of objMyObject)
Try
Dim reader As System.Xml.XmlReader
reader = System.Xml.XmlReader.Create(str_XmlFullFilePath)
Dim mySerializer As XmlSerializer = New XmlSerializer(GetType(System.Collections.Generic.List(Of objMyObject)))
objListFromXml = CType(mySerializer.Deserialize(reader), System.Collections.Generic.List(Of objMyObject))
Catch
'don't do anything. If error occurs, return an empty object
End Try
I may have some typos above. I replaced all my variables with more generic ones.
Tuesday, December 27, 2011
SQL to ORDER BY datetime Field by date
It's tricky to order by a datetime field by date because the GROUP BY clause attempts to group by seconds instead of days. My solution is:
SELECT
distinct Convert(varchar(10),Tasks.DateCreated,101) As Date,
Count(Convert(varchar(10),Tasks.DateCreated,101)) As DateCount
FROM Tasks
GROUP BY Convert(varchar(10),Tasks.DateCreated,101)
SELECT
distinct Convert(varchar(10),Tasks.DateCreated,101) As Date,
Count(Convert(varchar(10),Tasks.DateCreated,101)) As DateCount
FROM Tasks
GROUP BY Convert(varchar(10),Tasks.DateCreated,101)
Wednesday, June 22, 2011
Output a DataTable in Random Order - VB.NET
To change the order of a DataTable to random, you need to change the DataTable to a DataView, add a column to the DataView, populate the fields of that column with random numbers, sort the DataView by that column, and then change the DataView back into a DataTable. The good news is this can be done in just a couple lines of code.
Dim myDataTable As DataTable
myDataTable = Whatever your data table is
myDataTable.Columns.Add(New DataColumn("RandNum", GetType(Integer)))
Dim i as Integer
Dim rndNum as New Random()
For i = 0 to myDataTable.Rows.Count - 1
myDataTable.Rows(i)("RandNum") = rndNum.Next(10000)
Next i
Dim myDataView as DataView = myDataTable.DefaultView
myDataView.Sort = "RandNum"
myDataTable = myDataView.ToTable()
Monday, March 14, 2011
Microsoft Expression Locks Up When Saving Page
If Microsoft Expression locks up, freezes, or crashes when you are trying to save an .aspx .master or other type of page, you are not alone.
Fix:
In Expression, Click --> Tools --> Application Options --> Configure Editors.
For each file extension, click New Editor --> Open as XML. Move the XML editor to the top so it says (default).
Hope this helps
Fix:
In Expression, Click --> Tools --> Application Options --> Configure Editors.
For each file extension, click New Editor --> Open as XML. Move the XML editor to the top so it says (default).
Hope this helps
Monday, January 17, 2011
Outputting Tableless HTML Navigation with ASP>NET
If you are reading this, you are probably desperately trying to find a way to implement site navigation in an unordered list. You've probably also wasted several hours on the internet learning the basics of the DataList and DataTable controls built into ASP.NET; only to learn those two controls are contrived in such a way as to only output html in a table based format.
The solution is to use an asp:repeater. Here is a really well written article describing what I agree is the best method for outputting site navigation in an ordered list format.
The solution is to use an asp:repeater. Here is a really well written article describing what I agree is the best method for outputting site navigation in an ordered list format.
- Output your data to an xml sitemap
- Display the sitemap on the page as an unordered list using a Repeater .
Sunday, August 22, 2010
New Stylesheet for PORDL
So, I spent the whole day Sunday making a new Generic XSL stylesheet for PORDL. I built javascript into the XSL that ticks through the nodes showing only one at a time. I was pleasantly surprised that they worked great out of the box for Picasa and FlickR gallery feeds.
PORDL makes it easy to embed the gallery with just one line of code:
<script type='text/javascript' src='http://pordl.com/js.aspx?id=289' ></script>
Subscribe to:
Posts (Atom)